Android volley get callback when all requests finish
Asked Answered
D

1

3

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.

Danyelldanyelle answered 21/6, 2013 at 18:54 Comment(0)
C
8

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.

Collected answered 21/6, 2013 at 19:10 Comment(2)
I used an AtomicInteger because there can be concurrency issues.Danyelldanyelle
Good answer! Spent a while looking for the solution, but this is simple and straightforward.Meir

© 2022 - 2024 — McMap. All rights reserved.