问题描述
限时送ChatGPT账号..我正在使用 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屋!
更多推荐
[db:关键词]
发布评论