Difference between 'setExact' and 'setAlarmClock'

Viewed 5237

In my application which was supposed to trigger an alarm at a specified time, alarm whose purpose was to inform the user via a Notification, I despaired at obtaining a non precise result. The alarm was ringing, but not at the specified time. This was systematic when the time between the setting of the alarm and the time it was supposed to go off was long. For this, I was using setExact(RTC_WAKEUP,time,intent). After many attemps to make it work, I finally saw and tried the setAlarmClock function, and everything went fine!!

According to the javadoc, setAlarmClock is identical to setExact except that it implies RTC_WAKEUP. As far as I see, at least one other difference exists. Does anyone know it?

2 Answers

Doze mode, introduced in Android 6.0 (API level 23), adds further restrictions to those outlined above: (TL;DR: only setAlarmClock triggers in doze mode, and adds a system icon)

Doze restrictions

The following restrictions apply to your apps while in Doze: [...]

  • The system ignores wake locks.
  • Standard AlarmManager alarms (including setExact() and setWindow()) are deferred to the next maintenance window.
    • If you need to set alarms that fire while in Doze, use setAndAllowWhileIdle() or setExactAndAllowWhileIdle().
    • Alarms set with setAlarmClock() continue to fire normally — the system exits Doze shortly before those alarms fire. [...]

The devices enter the low-power doze-state with periodic wake-ups to perform the other alarms etc.

Related