java – AlarmManager和Handler WakeLock之间最好的是什么?

我正在使用我的Android服务处理器,每隔60分钟(1小时)重新进行一些操作,使用PartialWakeLock保持手机不睡觉.但这会导致大量电池使用.

所以决定研究一下AlarmManager(我是noob),someone wrote here对于这类东西来说是完美的..

但现在在网上阅读我发现谁使用AlarmManager,仍然需要一个WakeLock.这是真的吗?

每60分钟(1小时)运行一个循环的最佳方法是什么,而不会杀死电池?

感谢名单

附:

AlarmManager Android Developer

The Alarm Manager holds a CPU wake lock as long as the alarm
receiver’s onReceive() method is executing. This guarantees that the
phone will not sleep until you have finished handling the broadcast.
Once onReceive() returns, the Alarm Manager releases this wake lock.
This means that the phone will in some cases sleep as soon as your
onReceive() method completes. If your alarm receiver called
Context.startService(), it is possible that the phone will sleep
before the requested service is launched. To prevent this, your
BroadcastReceiver and Service will need to implement a separate wake
lock policy to ensure that the phone continues running until the
service becomes available.

但似乎我需要2个唤醒锁而不是使用处理程序的1个唤醒锁……这是真的吗?

解决方法:

我做了很多测试,这是结果:

-Alarm Manager比使用处理程序唤醒锁可以节省更多电量,以便进行长时间操作.

但是您必须对警报启动的活动/服务使用额外的唤醒锁定,因为警报管理器唤醒锁定不会覆盖它.

即使这种方法使用两个WakeLock,电池似乎更高效,寿命更长!在测试期间(2天),AlarmManager使用比其他方法少6倍的电池.在我自己的情况下……

希望这可以帮助一个人!

上一篇:Operation category READ is not supported in state standby. hdfs改变standby状态为active


下一篇:ubuntu下安装Apache+PHP+Mysql