Callback if RequestQueue Volleyball is performed with all its tasks?

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

+4
source share
2 answers

Save the number of queries in a member variable and decrease each time the query ends, and when the counter goes to 0, you're done! I do not know what caused the callback, which keeps track of all requests and returns 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 -- 
+5
source

I have found another way for me. It works great.

 RequestQueue queue = Volley.newRequestQueue(getApplicationContext()); final AtomicInteger requestsCounter = new AtomicInteger(0); for (String data: someArray) { requestsCounter.incrementAndGet(); queue.add(new StringRequest( Request.Method.GET, "https://stackoverflow.com", response -> { ...some stuff for response }, error -> { ...catch error here } )); queue.addRequestFinishedListener(request -> { requestsCounter.decrementAndGet(); if (requestsCounter.get() == 0) { ...all requests are done } }); } 
0
source

Source: https://habr.com/ru/post/1492040/


All Articles