本文介绍了AlarmManager和Handler + WakeLock之间最好的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的Android服务使用了一个处理程序,该处理程序每​​60分钟(1小时)会重复执行一些操作,并带有PartialWakeLock来保持手机不休眠。但这会导致大量的电池消耗。

I'm using for my Android Service an Handler that reapeat some operation each 60 minutes (1 hour), with a PartialWakeLock to keep the phone not sleeping. But this cause a lot of battery usage.

因此,决定研究有关AlarmManager(我是菜鸟)的原因是,非常适合这类事情。

So a decided to study about AlarmManager (i'm noob) that someone wrote here to be perfect for this kind of things..

但现在继续阅读在网上,我发现谁使用AlarmManager,仍然需要WakeLock。是真的吗

But now reading along the web i find that who uses AlarmManager, still need a WakeLock. Is it true?

在不消耗电池电量的情况下,每60分钟(1小时)运行一次循环的最佳方法是什么?

What is the best way to run a cycle each 60 minutes (1 hour), without kill the battery?

感谢

PS

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

But so seems that i need 2 wakelock vs just 1 wakelock using handler....is it true?

推荐答案

我进行了许多测试,结果是:

I have made many test and this is the result:

-警报管理器保存更多

但是您必须对由警报启动的活动/服务使用额外的唤醒锁,因为警报管理器唤醒锁

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.

即使这种方法使用两个WakeLock,电池也似乎更有效且寿命更长!在测试期间(2天), AlarmManager使用的电池比其他方法少6倍。就我自己而言...

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!

这篇关于AlarmManager和Handler + WakeLock之间最好的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 06:51