简体   繁体   中英

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.

To avoid adding duplicates to the requestQueue , I'm looking for something like the following pseudo-code:

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

I'd like to avoid using requestQueue.cancelAll() .

Any ideas how to avoid duplicates in a RequestQueue ? Thanks in advance!

After trying different solutions, I chose requestQueue.cancelAll() and it works as expected.

For further information, check the docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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