Home » Android » android – AlarmManager does not work when app is force closed

android – AlarmManager does not work when app is force closed

Posted by: admin June 15, 2020 Leave a comment


Documentation for AlarmManager startes that

Note: The Alarm Manager is intended for cases where you want to have your application code run at a specific time, even if your application is not currently running. For normal timing operations (ticks, timeouts, etc) it is easier and much more efficient to use Handler.

However, once my application is closed (force close from task manager) my alarm does not work and the OnReceive method is never called inside the broadcast receiver.
I am targeting 4.x.

What’s happening?

How to&Answers:

What @Shrikant says is pretty much the answer.

The longer verison is that it is assumed by Android that something is amiss with the app if the user had to force close it manually. Therefore all activities (BroadcastReceiver’s, alarms, etc) related to the app will not be initiated until the app is run manually by the user at least once. For example, app’s boot BroadcastReceiver will not be called when device is turned off and on in this state until the user runs the app, then the next device boot event will be delivered to the app’s BroadcastReceiver.

This behavior is confirmed as by design by Android framework devs: https://groups.google.com/forum/?fromgroups=#!topic/android-developers/anUoem0qrxU

*edited for grammar & added an example behavior