与总是在GPS的Andr​​oid服务 [英] Android service with always on GPS

查看:132
本文介绍了与总是在GPS的Andr​​oid服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Android应用程序是迄今为止合作得非常好。它包含了本地服务,这是负责获取用户的位置,每隔几分钟,该中继通过UDP到这是在翻显示Web应用程序中地图上的收集服务器。

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.

该应用程序需要不断运行,除非用户明确签署了应用。目前,它似乎OS正在关闭服务,并根据需要重新启动它。我可以看到这一点,因为通常它会始终报告它的位置,每2分钟。相反,有在这些间隔的间隙。

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.

于是我找了一些建议。我怎么能写一个(在电池的费用不幸)可以保持始终运行,集中在位置服务就足以在2分钟的时间间隔发送准确的修补程序的服务。

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.

我有一个很好的工作code基至今,因此,如果证实在那里我目前用code会有所帮助,不要犹豫,问。

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.

推荐答案

您最好的选择是使用的 AlarmManager 醒来每隔两分钟,做一些处理和快回去睡觉了。

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

如果你认为你是铁杆,你甚至可以使用唤醒锁定,但将保持手机的CPU上坚持原来毫不手软。你不希望出现这种情况。

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.

这篇关于与总是在GPS的Andr​​oid服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆