I have made an alarm clock app that uses AlarmManager
to place alarms. There is a broadcast receiver that receives the alarm broadcast, and then starts a foreground service.
Consider this situation: I do a fresh installation of my app on a device and add an alarm. I let a few seconds pass by, open a terminal window, and type the following command: adb shell dumpsys alarm
. In the list, I can find the alarm registered by my app.
Now, I close the app (clear it from recents), make sure the alarm process is dead from Android Studio logcat, and again type the above command. I cannot find my alarm in the list! The alarm was there just a few seconds back, and now it is not there.
So I open the app again, delete this alarm, and add another alarm. With dumpsys
, I can find my alarm in the list. I close my app and again execute dumpsys
, only to find that this time, my alarm is there in the list. When the time arrives, the foreground service starts properly.
Why is the alarm getting cancelled after I close the app in case of a fresh installation?