Alarms
Alarms
Alarms
Alarms and
Schedulers
Lesson 8
BroadcastReceiver
BroadcastReceiver
wakes up the app
wakes up
and delivers the
delivers notification
notification.
Activity creates Alarm triggers and
a notification and sends out Intent.
sets an alarm.
App may be
destroyed so….
This work is licensed under a Creative
Android Developer Fundamentals V2 Alarms Commons Attribution 4.0 International 6
License.
Benefits of alarms
AlarmManager alarmManager =
(AlarmManager) getSystemService(ALARM_SERVICE);
1. Type of alarm.
2. Time to trigger.
3. Interval for repeating alarms.
4. PendingIntent to deliver at the specified time
(just like notifications).
● setInexactRepeating()
○ repeating, inexact alarm.
● setRepeating()
○ Prior to API 19, creates a repeating, exact alarm.
○ After API 19, same as setInexactRepeating().
setInexactRepeating(
int alarmType,
long triggerAtMillis,
long intervalMillis,
PendingIntent operation)
alarmManager.setInexactRepeating(
AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime()
+ AlarmManager.INTERVAL_FIFTEEN_MINUTES,
AlarmManager.INTERVAL_FIFTEEN_MINUTES,
notifyPendingIntent);
This work is licensed under a Creative
Android Developer Fundamentals V2 Alarms Commons Attribution 4.0 International 24
License.
More Alarm
Considerations
boolean alarmExists =
(PendingIntent.getBroadcast(this,
0, notifyIntent,
PendingIntent.FLAG_NO_CREATE) != null);
alarmManager.cancel(alarmPendingIntent);