如果 Volley RequestQueue 完成所有它的任务,回调? [英] Callback if Volley RequestQueue is done with all it's tasks?

查看:29
本文介绍了如果 Volley RequestQueue 完成所有它的任务,回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 android 的 volley 网络库.我正在寻找一种在一堆请求完成时获得通知的方法,而不是单独检查所有响应侦听器(我也这样做).有没有一种简单的方法可以在所有任务完成后从队列中获取回调?

I am using the volley networking library for android. I'am looking for a way to get notified when a bunch of requests are finished, rather than checking all the response listeners individualy (which i also do). Is there an easy way to get a callback from the queue when all tasks are done?

推荐答案

将请求计数保存在成员变量中,并在每次请求完成时递减,当计数器变为 0 时,您就完成了!我不知道跟踪所有请求并在最后返回的回调公开.

Keep the requests count in a member variable and decrement everytime a request finishes, and when the counter goes to 0, you're done! I'm not aware of a callback exposed that tracks all the requests and comes back at the end.

int requestPending= 0;
for(int i=0;i<numberOfRequests;i++)
{
    requestQueue.add(request);
    requestPending++;
}
// For each requestQueue item finished onResponse received, do requestPending --

这篇关于如果 Volley RequestQueue 完成所有它的任务,回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆