Search code examples
androidalarmmanagerpower-off

Android: Fire all missed alarms when device turns on


In my application the user has set some reminders and I have to alarm them when the time has come. Currently I'm using AlarmManager.RTC as a type of AlarmManager

am.set(AlarmManager.RTC_WAKEUP, date.getTimeInMillis(), pendingIntent);

it in working as per instruction

// Sets an alarm - note this alarm will be lost if the phone is turned
// off and on again

is there any way the I can fire missed alarms when I turn on the device?

Please note that I don't want to wakeup the device, I just wanted to remind them when they turn on the device.

PS: I have read the documentation http://developer.android.com/reference/android/app/AlarmManager.html#RTC, but I didn't find my option.


Solution

  • is there any way the I can fire missed alarms when I turn on the device?

    Step #1: Have some way of tracking, yourself, what is missed, such as by tracking event status in a database.

    Step #2: Set up a BOOT_COMPLETED BroadcastReceiver to find when the phone is rebooted. In there, schedule any alarm(s) that are still in the future, and decide what to do about alarms that occurred in the past but were missed (e.g., raise a Notification pointing out the missed events).