I have been using volley networking library for some time now. To show the users that their request is being sent, I show them an indeterminate progress bar which I hide either inonResponse
or onErrorResponse
.
Bot now, I want to show the users the progress of the request and update the progress of the progress bar. In essence, I don't want to use an indeterminate again.
Say I am making this request:
/ Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
String url ="http://www.google.com";
//Show progressBar here
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//I Hide progressBar here, and parse and display the response.
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//I Hide progressBar here also and show a dialog to retry.
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);
How can I update the progress of the progressBar?
publishProgress
method in an AsyncTask, but if needed, that could be added to an extension of theRequest
class of Volley – KerbstoneparseNetworkResponse
method, you'd need to calculate the length of the string, then estimate how much of it has been processed. android.googlesource.com/platform/frameworks/volley/+/master/… – KerbstoneparseNetworkResponse
just as the name implies, the response has been gotten already, right? So except I am wrong updating a progressBar for an already complete request is pretty useless. I was thinking something like when you are downloading a file, you can see the progress of the download until it's complete. – Mosley