Android volley get callback when all requests finish

扶醉桌前 提交于 2019-12-06 06:35:06

问题


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.



来源:https://stackoverflow.com/questions/17242432/android-volley-get-callback-when-all-requests-finish

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!