Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset alarm if app is force closed in android

The alarms set by my app using AlarmManager are cleared if

  1. The user force closes my app in the settings.
  2. Some task killer app auto-killed my app process.
  3. Android itself killed my app, because of the need of memory for front apps.

Please tell me how do I detect it? rather how to set my alarms so that all these cases dont affect my alarms.

like image 429
John Nash Avatar asked Dec 26 '12 13:12

John Nash


1 Answers

The user force closes my app in the settings.

Yes, this clears alarms.

Some task killer app auto-killed my app process.

This does not clear alarms on any recent version of Android.

Android itself killed my app, because of the need of memory for front apps.

This does not clear alarms.

Please tell me how do I detect it?

Maintain a record of when your alarm last occurred (e.g., in SharedPreferences). When your code runs (e.g., LAUNCHER activity is started), check the last-alarm time. If it was a long time ago, you know that your alarms were cleared, and so you need to reschedule them.

rather how to set my alarms so that all these cases dont affect my alarms.

This is not possible. There are few cases where the alarms actually are cleared (reboots and Force Stop), and there is nothing you can do to prevent your alarms from being cleared in those cases.

like image 116
CommonsWare Avatar answered Oct 04 '22 02:10

CommonsWare