Scheduling repeating alarms
As well as setting a one-off alarm, we have the option to schedule repeating alarms using setRepeating()
and setInexactRepeating()
. Both methods take an additional parameter that defines the interval in milliseconds at which to repeat the alarm. Generally, it is advisable to avoid setRepeating()
and always use setInexactRepeating()
, allowing the system to optimize device wake-ups and giving more consistent behavior on devices running different Android versions:
void setRepeating( int type, long triggerAtMillis, long intervalMillis, PendingIntent operation); void setInexactRepeating( int type, long triggerAtMillis, long intervalMillis, PendingIntent operation)
AlarmManager
provides some handy constants for typical repeat ...
Get Asynchronous Android Programming - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.