i have a service that receives location updates every 1-3 seconds or so. the service is started from the main activity using a pending intent:
mFusedLocationClientFast.requestLocationUpdates(mLocationRequest, getPendingIntent());
where getPendingIntent() is a method that defines an action for my IntentService to handle in handleIntent()
however, a strange thing i noticed is that every time the IntentService handles a location update in handleIntent(), it's always immediately preceded by a call to onStartCommand() of the same service.
does anyone know why onStartCommand() needs to be called every time the service handles an intent?
thanks
An IntentService is, simply, a Service that runs
onHandleIntenton a worker thread. The mechanism by which a Service receives an intent isonStartCommand.In an IntentService, the
onStartCommandmethod forwards the intent to theonHandleIntentmethod.The code is here
It is puzzling, to me, that the designers of the
IntentServicedid not make its implementations ofonStartCommandandonStartfinal