Laser42
Laser42

Reputation: 744

Which type of Android Services should I use?

I try to get services into my weather application. Let's assume that user has set up locations (cities list), and that he tap an Update button. In my case, this tap is caught by MainActivity. After that, the application should read from sqlite user locations to update weather data, loop through this list of locations, for each of them send request to weather provider, parse json and put weather data into database. On success, the current view should be updated to show data that was just received. How should I separate all this logic between MainActivity and services, and which type of services should I use? I think, it can be intent service to get the weather from provider and insert it into database, and bound service to update user layout (view). Also, when we have a weather update schedule, should be created a service, that runs permanently in the background, and launches weather update process automatically. Which type of android service schould be used in this case?

Thank you.

Upvotes: 0

Views: 484

Answers (1)

Vyacheslav
Vyacheslav

Reputation: 27211

There are several methods. Just some of them.

  1. Bind service and Activity ( imho, the ugliest)
  2. Send broadcast intent between activity and service. Lags appear while datea transfer.
  3. Send message between of them.
  4. And, imho, the most useful way (that doesn't exist is specifications) is to set both Activity and Service as interfaces (listeners) that are stored inside Application class.
  5. By the way you can send data via both singleton and application class.

Upvotes: 1

Related Questions