如果 Volley RequestQueue 完成所有它的任务,回调?

编程入门 行业动态 更新时间:2024-10-25 11:33:32
本文介绍了如果 Volley RequestQueue 完成所有它的任务,回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-23 00:44:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1031249.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:回调   Volley   RequestQueue

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!