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
Related
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?
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 :-(
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 followed this post http://it-ride.blogspot.com/2010/10/android-implementing-notification.html to implement a Notification Service. It uses AlarmManager and Wakelock to start a service. When you restart the device the alarm is set correctly or when you open the app the alarm is set, but if you force close the app the alarm is gone. I would like to reset the alarm after the app is forced stopped. How can I do this?
According to Google's Android engineers, an app that is forcefully stopped will not start again until the user invokes it.
Check out the following response found 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.