What's the best between AlarmManager and Handler+WakeLock?

有些话、适合烂在心里 提交于 2019-12-05 19:53:20

I have made many test and this is the result:

-Alarm Manager save more battery than using handler+wakelock for long timing operation.

But you must use an additional wake lock to your activity/service started by the alarm, because the alarm manager wake lock doesn't cover it.

Even of this method uses two WakeLock the battery seems to be more efficient and with more life! During the tests (2days) the AlarmManager use 6 time less battery than other method. In my own case...

Hope this can help some one!

I suggest you to use AlarmManager to handle events with 1 hour interval.

Because we don't know exactly what you what to achieve we can't provide a more in deep answer/suggestion sorry.

I am not sure if it is still relevant,

but the answer is: using AlarmManager is preferred. You only need a WakeLock to keep phone running after AlarmManager has woken it up to send an Intent to your receiver and until service has finished its work. So phone will be awake only for a couple of milliseconds, compared to "all the time".

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