Search code examples
androidandroid-6.0-marshmallowandroid-alarmsandroid-doze-and-standby

Difference between setAndAllowWhileIdle and setExactAndAllowWhileIdle


What is difference between AlarmManager.setAndAllowWhileIdle() and AlarmManager.setExactAndAllowWhileIdle()? How does these both affect Doze mode introduced in Android 6.0 (Marshmallow) API?


Solution

  • 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.