Why does Android's alarm manager forgets alarms? - android

I set alarms to notify the user on different times. I check with "adb shell dumpsys alarm" and they look like
RTC_WAKEUP #2: Alarm{433c7328 type 0 com.app.package}
type=0 whenElapsed=89936417 when=+9h8m5s417ms window=-1 repeatInterval=0 count=0
operation=PendingIntent{42e8e7f8: PendingIntentRecord{42deb070 com.app.package broadcastIntent}}
Sometimes they stay and work for at least 2 days (I didn't test longer), sometimes they are all gone after a few hours or so, even before the first notification should have taken place and "adb shell dumpsys alarm" doesn't show any of my entries anymore. (I tested with 2 devices, Android 4.0 and 4.4)
I do know that the alarm manager forgets the entries after a reboot of the device and I took care of this case and re-add them afterwards. But obviously there are other cases when the alarm manager forgets entries without having rebooted. I would like to know which cases these are and how to handle them.

From AlarmManager
This class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future. When an alarm goes off, the Intent that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running. Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.
it will work until your application has been killed or device has been rebooted.(If you removed an application from recent list, or from Application Manager you kill the app. That means you are force fully killed the application. and Then AlarmManager of your application has been removed.)
in some cases when your app is in background android kill it to access more ram.
You can read more about application kill at How to create a persistent AlarmManager, and How to save Alarm after app killing?

Related

Android AlarmManager is cancelling alarm when app is dead after fresh install of app on device

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?

how to trigger a react-native app to wake up? (for alarm)

Basically I am trying to add an alarm feature to my app.
set time & date, save >> turn the app off >> when it's the time, RING-RING-!
But to do this, the app should wake itself to run the alarm feature; otherwise it won't work unless the app is running at the alarm time.
Any regular alarm apps just open itself when its the time, even when the app was not running on the phone. does anyone here know how apps self-wake?
Thanks very much
Use AlarmManager to do alarm envenif the app is not running.
But if the machine reboot, it will not work. So we need to run a service to register alarm when machine boot complete.

Android Alarm Manager not being triggered

I have my app installed in 2000 devices. In most of them it is working great. But some users (maybe 100) report me that the app is not updating correctly.
I found out that the problem is that the AlarmManager is not triggering an Alarm. The app is supposed to update data every 15 minutes so I use an Alarm Manager for that.
With no reason, it seems like it stops working after a while of running and it never starts again unless the phone is rebooted. Then it works again for a while and finishes stopping, too.
I don't have access to those devices but the users tell me they don't have any task manager or background cleaners. And in case they have them, then my app is in the 'ignore list'.
I have tried to emulate this scenario but I cannot.
It seems like the app is killed and the alarm managers don't work. By the way, those killed apps don't receive GCM events either.
So the questions are:
Is there anyway to prevent the app from being killed or to ensure the alarm is triggered at the time I set.
Can I use broadcast events like Screen-on, Screen-Off or Telephony incoming events to check if the alarm has been triggered and in case it is not to do it at that moment? I am not sure if this would work because if my app is killed then probably it will not receive any event, correct?

How to setup alarms again after reboot

I am building an alarm clock application, then is purely dependent on alerting the user during the proper time an alarm is to go off. However, reading about AlarmManager, it appears that at device reboot, all alarms are removed.
As my app would then be rendered worthless if all the users alarms were erased, how can I prevent that from happening/ensure that all alarms are always in place whether reboot or not?
Have your application handle the ACTION_BOOT_COMPLETED intent to install alarms at boot:
Broadcast Action: This is broadcast once, after the system has finished booting. It can be used to perform application-specific initialization, such as installing alarms. You must hold the RECEIVE_BOOT_COMPLETED permission in order to receive this broadcast.

Reminder application

I am developing a reminder application. I am generating notifications using notification manager class, when the timeline crosses.But if my cell phone is switched off ,I am unable to see these notifications. Not even when i switch it on again.
Even if i switch it off and switch on again, i think the pending intents are destroyed and no notification is generated.
How do i get it when the phone is switched on again ?
Have a look at the AlarmManager:
From http://developer.android.com/reference/android/app/AlarmManager.html:
This class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future. When an alarm goes off, the Intent that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running. Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.

Categories

Resources