Android volley get callback when all requests fini

2020-07-23 05:22发布

问题:

I am using volley to queue a series of requests. I am showing a progress dialog to the user when these requests are happening. Is there a way I can check when all these requests are finished. This is what I want.

//Show progress bar
for(int i=0;i<size;i++)
{
    //create request and add the request
    requestQueue.add(request);
}
// When last request finsihes dismiss progres bar

Is there a solution to this problem.

回答1:

You can keep the total number of requests in a member variable :

int pendingRequests = 0;

//...
for(int i=0;i<size;i++)
{
    requestQueue.add(request);
    pendingRequests++;
}

Then each time a request finishes you decrement the counter, and if it reaches 0, you know that all requests are done.