1

I wish to show a status bar notification at 12 pm everyday and hence, I'm creating an AlarmManager which fires an IntentService which will show some notification.

I've added Boot completed receiver and the AlarmManager is registered when the app gets lauched. Everything is working fine and the Notifications are shown everyday at 12 pm even when app is not in foreground (expected behaviour).

The problem is, whenever I clear the App data in Application settings, The AlarmManager no longer triggers the Application notifications. However, When I launch the app again, the App starts working with the notifications everyday with an expected behaviour.

Could anyone please help me with this issue? Is there a workaround to ensure that AlarmManager is triggered irrespective of these conditions.

Tim
  • 41,901
  • 18
  • 127
  • 145
Adithya Upadhya
  • 2,239
  • 20
  • 28

2 Answers2

3

Is there a workaround to ensure that AlarmManager is triggered irrespective of these conditions?

No. When you press 'Clear data', not only is the app's data cleared, its processes are also killed. When that happens, scheduled alarms are killed with it.

It's not strange that this happens. A running app might need data that you cleared, if it doesn't find that data, it could crash. Killing the app will prevent those crashes.

Community
  • 1
  • 1
Tim
  • 41,901
  • 18
  • 127
  • 145
  • Is there any method in which I could perform some action when the App is forcefully Killed (Such as resetting the alarm when app is killed)?? Any provision for that provided by Android? – Adithya Upadhya Sep 20 '16 at 12:28
  • @oathkeeper no, you're not allowed to do that. That would beat the purpose of killing the app – Tim Sep 20 '16 at 12:29
  • Thank you for your help. Seems like killing the app is the Achilles heel of my app :( – Adithya Upadhya Sep 20 '16 at 12:31
  • @oathkeeper on stack overflow, instead of saying "thanks", you can show gratitude by clicking the `^` arrow next to the answer. See http://stackoverflow.com/help/someone-answers (you can do this for multiple answers) – Tim Sep 20 '16 at 12:39
  • Ditto on that as *that* is how we roll here. Nice answer. – Drew Sep 20 '16 at 14:20
2

This is normal behaviour. If the user voluntarily force stops or clears the data of the application,then it should be stopped. android system kills the entire task ,No services or broadcasts are allowed to run until an activity is run again. so you can't do anything to prevent this. see the qn answered here.

Community
  • 1
  • 1
droidev
  • 7,352
  • 11
  • 62
  • 94
  • Is there any method in which I could perform some action when the App is forcefully Killed (Such as resetting the alarm when app is killed)?? Any provision for that provided by Android? – Adithya Upadhya Sep 20 '16 at 12:29
  • @oathkeeper no, I dont know if there is any hacky methods, but android doesn’t allow you do anything directly. – droidev Sep 20 '16 at 12:32