Android Periodic GPS location updates with AlarmManager inside a Service

前端 未结 2 1608
迷失自我
迷失自我 2020-12-15 01:38

I read a lot of questions on here but couldn\'t figure out what the problem is.

I\'m writing a field service application for Android. In one of the Activities (MyAct

2条回答
  •  粉色の甜心
    2020-12-15 02:21

    First, you cannot register for location updates, then shut down the service. At best, you will leak threads. At worst, Android will terminate your process (thinking there is nothing running in it) and you will not get the update. Also, GPS takes a while to warm up, so you might not get a fix within 20 seconds, particularly in an urban setting. Also, you have to make sure the device stays awake while you are trying to collect a fix.

    As a result, getting periodic location fixes in the background is a rather complicated problem.

    I wrote a now-discontinued LocationPoller to try to address this, and another developer has forked and extended it. You could try the fork or simply use it as a source of ideas.

提交回复
热议问题