2

I want to create an Alarm for Android.

I've used so far an AlarmManager that sets on the given time and day. And onReceive(), I have a NotificationManager that warns for a specific event.

My problem is that if the event is set for a week or month later, I may restart my device and my alarm will be lost.

Can someone explain me how can I save this alarm and restore it after reboot?

Sujit Devkar
  • 1,055
  • 3
  • 11
  • 19
user3624383
  • 87
  • 2
  • 13
  • refer accepted answer of this [link](http://stackoverflow.com/questions/17673746/start-alarmmanager-if-device-is-rebooted) – Gentle Mar 22 '17 at 09:34

1 Answers1

3

you need to use a broadcast receiver that listens for the broadcast

android.intent.action.BOOT_COMPLETED

then restart your alarms from your broadcast receiver

tyczj
  • 66,691
  • 50
  • 172
  • 271
  • @CommonsWare the sample project you mention has a dead link. Please advise. – AJW Jul 04 '18 at 02:33
  • @AJW: Sorry! I got rid of that sample project from the book, as it uses the now-deprecated `WakefulBroadcastReceiver`. Here is a link to that project from an older edition of my book: https://github.com/commonsguy/cw-omnibus/tree/v8.8/AlarmManager/WakeCast – CommonsWare Jul 04 '18 at 10:45
  • @CommonsWare No apology necessary! You go above and beyond to help others on SO. I appreciate the link to the older edition. Cheers! – AJW Jul 04 '18 at 15:46