开发者

Android service with always on GPS

开发者 https://www.devze.com 2023-03-24 22:11 出处:网络
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 c

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 ru开发者_运维问答nning 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消