Search code examples
androidalarmmanager

alarm manager phone rebot


I am working on an app that should reappear after every 15 days, my app is working correctly, but what will happen if the phone reboots, I am using broadcast manager to restart the activity. But is there any way that the alarm remain at the same value e.g. if phone reboots after 3 days of previous event, then the next alarm should fire in 12 days.

I haven't seen this exact question, people generally ask about broadcast receiver, which I am already done. Any pointers?

Is storing the alarm time in a file is a good idea? But then what goes in AlarmManager.INTERVAL_DAY*14 ? My sample alarm manager is below:

am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY*15, pi);                          

Solution

  • You'll need to save the value in SharedPreferences and restart the app with a modified alarm.

    I'd save the value at some interval and also detect phone shutdown (using broadcasts)