Location listener works from a Service but not an IntentService

后端 未结 1 1385
情话喂你
情话喂你 2021-02-06 15:44

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

相关标签:
1条回答
  • 2021-02-06 16:09

    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.

    0 讨论(0)
提交回复
热议问题