What is difference between AlarmManager.setAndAllowWhileIdle()
and AlarmManager.setExactAndAllowWhileIdle()
? How does these both affect Doze mode introduced in Android 6.0 (Marshmallow) API?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Refer to the documentation of AlarmManager
:
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.
Indeed, both the methods you mentioned specify that they behave like their counterparts without the "AndAllowWhileIdle" (set
and setExact
). So one of them will deliver the alarm at the exact time and the other will not be exact.