I have an app where I am trying to periodically get user location and send to server. I have a service attached to an AlarmManager
which executes every minute (for
As Pankaj Kumar notes, an IntentService
is not an appropriate solution for cases where the work to be done is intrinsically asynchronous. Once onHandleIntent()
returns, your service is destroyed.
Use a regular Service
, register for locations in onStartCommand()
, using a HandlerThread
for processing the results (so you can pass its Looper
into requestLocationUpdates()
). Once your location is received, or a suitable timeout is reached, do your work and call stopSelf()
on the service to shut it down.