Android service with always on GPS

浪尽此生 提交于 2019-12-12 05:39:32

问题


I've created an android app that is so far working quite well. It contains a local service which is responsible for getting the users location every couple of minutes and relaying that via UDP to a collection server which is in turned displayed on a web application map.

The app needs to be constantly running unless the user explicitly signs out of the application. Currently, it seems the OS is shutting down the service and restarting it as needed. I can see this because normally it would report its location consistently every 2 minutes. Instead, there are gaps in these intervals.

So I'm looking for some advice on how I can write a service which (at the battery's expense unfortunately) can stay running always and pool the location service just enough to send accurate fixes at a 2 minute interval.

I have a well working code base so far, so if demonstrating where I currently am with code would help, don't hesitate to ask.

Thanks in advance to those that lend a hand.


回答1:


Your best bet is to use the AlarmManager to wake up every two minutes, do some processing and quickly go back to sleep.

If you think you're hardcore, you could even use a wake lock, but that will keep the phone's CPU turned on persistently without mercy. You don't want that.



来源:https://stackoverflow.com/questions/6934991/android-service-with-always-on-gps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!