AlarmManager does not work when the application is closed

The documentation for AlarmManager begins with

Note. The alarm manager is designed for cases where you want your application code to run at a specific time, even if your application is currently not working. For normal synchronization operations (ticks, timeouts, etc.) it is easier to use Handler.

However, when my application is closed (forced to close from the task manager), my signal does not work, and the OnReceive method OnReceive never called inside the broadcast receiver. I am aiming for 4.x.

What's happening?

+6
source share
1 answer

What @Shrikant says is pretty much the answer.

The longer version is that Android assumes that something is wrong with the application if the user had to force close it manually. Therefore, all actions (BroadcastReceiver, alarms, etc.) associated with the application will not be triggered until the application is manually launched by the user at least once. For example, a BroadcastReceiver application download will not be called when the device is turned off and on in this state until the user starts the application, and then the next device download event will be delivered to the BroadcastReceiver application.

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

* edited for grammar and added example behavior

+10
source

Source: https://habr.com/ru/post/944372/


All Articles