Can anyone suggest a solution to this problem?
If you use the AlarmManager all added alarms are cleared if:
The device is rebooted
The app is updated
Force Stop of the app
Solutions for readding the alarms are easy for the first 2, but the 3. are a huge problem:
BOOT_COMPLETED Broadcast
PACKAGE_UPDATED Broadcat
????
So does anyone have a solution for 3?
I now that Force Stop of the app kills the complete app and the app and all broadcast are only getting active again if the user starts the app manually.
This is OK, but I need a way to readd my alarms to the AlarmManager after the user reopens the app.
For example:
User opens app and adds one alarm in 30 minutes
After 15 minutes a system app or task killer app force stops the app and all alarms are deleted
After 20 minutes the user opens the app again AFTER the force stop, now I want to readd the alarm to the AlarmManager
A solution would be to readd all alarms after every start of the app, but this isn't possible because it is a reminder app and some users have over 100 reminders added.
I can't add over 100 alarms on every start of the app.
So I need a way to see/check if my app was force stopped earlier.
Now after a force stop all "old" reminders/alarms are never getting active again. Only new created alarms are working.
Really bad user experience :-(
Related
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.
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.
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.
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?
I have an application already in the Play Store. Now, I am going to release an upgrade as part of which a new alarm has to be scheduled. A little context into the alarm:
When a user installs an app and logs in, this alarm gets scheduled for periodic background sync.
However how will I start this alarm for users who have already installed my app and are logged in? Alarm will eventually get started on next reboot but I would like to understand what is the right approach when trying to start an alarm immediately after an upgrade.
You could use a broadcast receiver and catch the Intent.ACTION_PACKAGE_REPLACED action to get this done.
example code can be found at http://alvinalexander.com/java/jwarehouse/android/core/java/com/android/internal/content/PackageMonitor.java.shtml
I use AlarmManager to issue local notifications to user. But if I kill my application using Settings->Apps->Stop, alarm manager seems to be destroyed and all the notification icons disappears from status bar.
It it normal? The idea of local notifications is to persuade user to start my great app if it's closed. And it seems odd for me that they are being wiped out if I kill the app.
If you KILL your application you also kill the AlarmManager.
There is nothing odd about it. You close the app by pressing the home button, not by killing it via the settings.
Use service to set AlarmManager and notification.
Also keep in mind that once device is restarted Alarm is cancelled.
So you will need to set broadcast receiver.
look at this Click here
I'm a newbie in android so please bear with me.
My Main activity creates and alarm in the alarm manager which supposed to fire in specific time, my main Activity also create Broadcast receiver which suppose to receive the Intent that the alarm fired, everything is working good until Task manager killing my App.
I've check the PendingIntent list in the AlarmManager and verify that my alarm is getting erased from the Alarm Manager, I try to add service and register alarm from the service, I've red that maybe because my IntentFilter of the Broadcast receiver is defined in code and not in manifest it get killed after app process is killed, and I'm stuck on this issue for two weeks :-(, with big confuse, my design is wrong ?
Here is my needs:
That the alarm will be very reliable, even if app is killed or even if phone is restart.
Same goes to the broadcast receiver.
Thank you in advance,
If the user task-kills or force-stops your application, your alarms are unregistered. And, on Android 3.1+, nothing of your app will run again until the user manually launches one of your activities.
There is nothing that you can do about this, other than to do your best to write a high-quality application that the user will have no need or wish to force-stop.