

Nowadays Robolectric is a de-facto standard in Android unit testing. You create the alarm, set it up and forget about it.

This is, if your application is compiled against KitKat or higher, you cannot rely on the accuracy of any method which is not setWindow or setExact. Bear in mind that for apps targeting API 19 and higher alarms are no longer exact, and they can (and will) be deferred under OS discretion with the purpose of saving battery. INTERVAL_HALF_HOUR, // consequent repetitions: every half hour alarmIntent // PendingIntent to launch on alarm ) Īnd that’s it! The Android system will call your PendingIntent once the timeout has been met. elapsedRealtime (), // first repetition: asap! AlarmManager.

ELAPSED_REALTIME_WAKEUP, // type: wake if device asleep SystemClock.
