收听网络位置更新时电池消耗
我有一个作为后台服务运行的应用程序,并不断侦听网络更新(课程位置)。该服务本身不持有任何唤醒锁。监听部分如下所示:
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 120000, 3000F, this);
我的 onLocationChanged()
方法正在做一些非常简单的事情(只是计算使用 Location.distanceTo()
到预先配置的位置的距离:
在查看电池统计数据时,该应用程序是一个摇滚明星 - 有时甚至更多CPU
,但“保持清醒”部分非常高,
并没有那么糟糕
我想使用 AlarmManager
每 2 分钟请求一次更新。拿到后就去睡觉,但我不确定这是一个好方法,
而且,我想检测设备何时处于运动状态,但这很可能是一个更大的杀手。
I have an application that is running as a background service and constantly listens to network updates (course location). The service itself doesn't hold any wake locks. The listening part looks like this:
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 120000, 3000F, this);
My onLocationChanged()
method is doing some very simple stuff (just calculating distance to a pre-configured location using Location.distanceTo()
:
When looking into the battery stats, the application is a rock star – sometimes even more than the display.
CPU is not that bad but the "Stay Awake" part is very high.
Is there a way to prevent this?
I thought to use the AlarmManager
to request an update every 2 minutes and then go to sleep after I get it, but I'm not sure that this is a good approach.
Also, I thought to detect when the device is in motion, but this will most probably be even a larger killer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你回答了你自己的问题。
这将是最好的方法。但不要将其设置为两分钟,而是将其设置为 10 分钟间隔。
I think you answered your own question.
That would be the best approach. But don't set it to two minutes, set it to 10 minutes intervals.