Android volley get callback when all requests fini

2020-07-23 05:41发布

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条回答
可以哭但决不认输i
2楼-- · 2020-07-23 05:50

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.

查看更多
登录 后发表回答