1

Is it good design to have multiple services running at a time to do multiple network calls from android application? In my application, when user logs in, there are several fields that needs to be populated from the response received from network calls, for which i am trying to make use of multiple services run at a time. If I do not run multiple services for this, the user may have to wait for long. On the other hand running multiple services at a time may not be good idea considering constraints with the mobile device. Any suggestions?

Kaps
  • 2,345
  • 2
  • 26
  • 37

1 Answers1

1

You can achieve the same thing using one service to spawn multiple threads. Why do you need multiple Services for this. Have a Service named BackgroundNetworkService. It basically spawn a thread to communicate to server and to refresh UI from background thread you can make use of Handler.

So As a flow it should be Activity -> Service -> Thread(Make Network call and Get the Response) -> Handler ( To Update the UI to show response)

Note : You can make use of Thread Pool to control the number of threads to run simultaneously.

Brijesh Thakur
  • 6,768
  • 4
  • 24
  • 29
  • 1
    how will you ensure that all the thread execution has completed and the service should be closed? – Kaps Sep 04 '13 at 12:47