0

I've an endpoint that provides the current weather using /current.json and any future day using future_n.json where n = number of days from today.

I do not have the ability to change the endpoints and want a list of these responses, so I can display the weather for the whole week. The issue is however, I have to wait for the responses of all of these to display the UI. I'm using the Volley lib to make my JSONRequests.

How should I structure the network calls that's considered best practice? Do I make the calls separately and add each response to a list, to update UI when the last call has been made? Any help is appreciated.

Haroon
  • 538
  • 2
  • 11

1 Answers1

1

I can think of two approaches:

  1. Make the calls one by one and update UI once all data are ready. Pros: you can easily stop and continue the calls later as well as handling the error. Cons: slow.

  2. Make the calls asynchronously and update UI respectively. Pros: fast. Cons: difficult to handle errors. Imagining if there is one call failed due to network issue. you need to decide whether to stop all other calls or show some error for that call only and continue with others.

Yang Liu
  • 1,300
  • 10
  • 14