我想制作一个每秒更新一次(更多电池消耗)或每分钟(更少电池消耗)的小部件。
我按照 this thread 中的方式进行了跟踪
,但仅每 30 分钟运行一次。
我配置的是,一旦 onUpdate 运行,它会在 1 分钟内更新,并且 onReceived 每 30 分钟运行一次。
谁能告诉我我做错了什么?
最佳答案
根据我的经验,AlarmManager
在间隔小于 1 分钟时不能正常工作(或根本不能正常工作)。此外:
Note: The Alarm Manager is intended for cases where you want to have your application code run at a specific time, even if your application is not currently running. For normal timing operations (ticks, timeouts, etc) it is easier and much more efficient to use Handler.
另外:
Note: Beginning with API 19 (KITKAT) alarm delivery is inexact: the OS will shift alarms in order to minimize wakeups and battery use. There are new APIs to support applications which need strict delivery guarantees; see setWindow(int, long, long, PendingIntent) and setExact(int, long, PendingIntent). Applications whose targetSdkVersion is earlier than API 19 will continue to see the previous behavior in which all alarms are delivered exactly when requested.
关于android - 为什么 Alarm Manager 仅在 30 分钟内更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20681667/