Why does the SyncService
example provided by Google below use a Service
instead of an IntentService
? It is my understanding that IntentServices
run in the background, while a regular Service
will run in the main thread. For something with no UI that just updates data, why would you want it run in the main thread? Doesn't that risk frame-drops?
Is it possible to have a standalone IntentService
? or does it need to be based off something running on the main thread? This is the only reason I can see why we would use a regular Service
above.
Objects do not run on threads. Methods do.
IntentService
inherits fromService
. The main lifecycle methods onService
, notablyonStartCommand()
are called on the main application thread.IntentService
happens to provide a background thread, which it uses to call youronHandleIntent()
method, triggered by a call toonStartCommand()
.You don't.
Because an
IntentService
is inappropriate here. Quoting the documentation that you linked to:IntentService
and the binding pattern do not work well together.From a threading standpoint,
onPerformSync()
is called on a background thread, supplied by Android. Hence, even ifIntentService
were not ruled out based upon binding, you do not need another background thread, sinceonPerformSync()
is already called on a background thread.