简体   繁体   English

Android / Java:如何避免RequestQueue中的重复项?

[英]Android/Java: How to avoid duplicates in a RequestQueue?

My app sends data to a server every few minutes. 我的应用每隔几分钟将数据发送到服务器。 It works fine as long as I'm online. 只要我在线,它就可以正常工作。 When I'm offline in between, it seems like the stringRequests are temporarily stored in the requestQueue and fired all together as soon as I establish the internet connection. 当我在两者之间处于离线状态时,似乎stringRequests临时存储在requestQueue并在建立Internet连接后立即将其全部触发。

To avoid adding duplicates to the requestQueue , I'm looking for something like the following pseudo-code: 为了避免将重复内容添加到requestQueue ,我正在寻找类似以下伪代码的内容:

if (!requestQueue.isRequestInQueue(stringRequest)) {
    requestQueue.add(stringRequest);
}

I'd like to avoid using requestQueue.cancelAll() . 我想避免使用requestQueue.cancelAll()

Any ideas how to avoid duplicates in a RequestQueue ? 任何想法如何避免RequestQueue重复项? Thanks in advance! 提前致谢!

After trying different solutions, I chose requestQueue.cancelAll() and it works as expected. 在尝试了不同的解决方案之后,我选择了requestQueue.cancelAll() ,它可以按预期工作。

For further information, check the docs . 有关更多信息,请检查docs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM