0

In my application, the functionality is as below:

  1. First I am creating JsonObjectRequest using Volley. This returns me the JSON data. Here I used this technique with callback to make sure I’m getting the response and then processing it further.

  2. From JSON data I received above (1), I get the multiple URLs from which I need to get more data. In the onResponse of the first request above (1), I am calling a method which creates new request queue and create and add requests for all these individual URLs to the same. My final objective is to display the data after I get the all the data from this step, i.e. multiple URLs.

What is happening: I’m able to fetch the data from (1) above and display correctly but it is not waiting for downloading the data from step (2) above. I guess I cannot add the requests in (2) in the request queue of (1) because first I need the urls from request 1 to process in request 2.

How can I wait in my application for data download complete from step (2) as well?

enter image description here

Let me know if the question is not clear. I’ll try to add more details.

Community
  • 1
  • 1
user846316
  • 6,037
  • 6
  • 31
  • 40

1 Answers1

2

You can try one of these...

  1. Check Volley - http request in blocking way if you like to handle RequestFuture objects.
  2. Maintain a counter, once all the requests are complete and counter is set to desired value you can process further. Something like below:

Not sure if you like this, but just a thought.

call("url", callback(){
     ++counter;
   if(counter == DESIRED_VALUE )
      displayData();
});

counter be a AtomicInteger

Community
  • 1
  • 1
Naveen
  • 830
  • 9
  • 19
  • Thanks for your answer. However it doesn’t solve my problem. RequestFuture blocks the app until the result is available. I don’t want that! It impacts the fluidity of the app. Regarding the counter thing, I’m not sure how would it work. In my case, there are two different request queues and second queue should start after first one is done. The second queue needs to have multiple requests. I want my data to be processed once second request is also complete. For now, it is progressing just after the first request is done! – user846316 Jul 26 '16 at 14:29