Ofek Agmon Ofek Agmon - 1 year ago 57
Android Question

Service vs IntentService in a case of location tracking service

I read about the differences between


The main thing I read is that
has a Workerhtread that the service runs in.

I need to have a service which run regardless of the application activities/ui, and keeps track of the user location.

The service will implement
and also
, and when running, will update a table with the location of the user all the time (until stopped).

Should I use

Answer Source

An IntentService is meant to be a fire and forget service, for relatively short tasks that may be repeated. Another important distinction is that an IntentService stops itself when onHandleIntent() returns. A regular Service doesn't stop unless you (or the android os) explicitly stop it.It sounds like you are planning on a long-running task that also runs when your app is not in the foreground.

In this scenario you definitely want to use a regular Service. You can still choose to perform the work in a separate thread by creating one inside the service and doing the work in there, but you don't necessarily have to. Remember that by default, a Service runs on the main thead.