setRepeating of AlarmManager not respond within the time indicated

自古美人都是妖i 提交于 2019-12-02 12:06:58

As of KitKat (API 19), alarms are inexacted and batched together to preserve battery life by minimizing the number of times the device needs to wake up.

From the AlarmManager documentation for setRepeating():

Note: as of API 19, all repeating alarms are inexact. If your application needs precise delivery times then it must use one-time exact alarms, rescheduling each time as described above. Legacy applications whose targetSdkVersion is earlier than API 19 will continue to have all of their alarms, including repeating alarms, treated as exact.

For more precision you will need to use setExact() and reschedule an alarm every time an alarm wakes up your app. Do so very carefully though, as setting frequent alarms (such as every 1 minute) will dramatically decrease your users' battery life.

From the setExact() documenation:

Note: only alarms for which there is a strong demand for exact-time delivery (such as an alarm clock ringing at the requested time) should be scheduled as exact. Applications are strongly discouraged from using exact alarms unnecessarily as they reduce the OS's ability to minimize battery use.

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