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.
Related
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'd like to know if it's possible to send a local notification to the device when the app have been opened then closed.
It works already when my app is opened and when it's in the background.
Thanks
Edit : I think i wasn't clear enough:
I want to send a local notification at a given time even if the app is not running at that time.
By "Local Notification" i mean a Notification (android class) created in my app and send by using an AlarmManager and a BroadcastReceiver.
closed -> killed the process of my app
Most means of "killed the process of [your] app" will leave your alarms intact, and so whatever you have scheduled will remain scheduled and keep being invoked as you set up.
I want to send a local notification at a given time even if the app is not running at that time.
Again, AlarmManager is not dependent upon your process being around, so long as it can invoke the PendingIntent that you supply. So long as the BroadcastReceiver you are using is registered in the manifest (and not via registerReceiver()), it should work fine.
If the user force-stops your app -- usually via the Settings app -- then not only will your alarms not be invoked, but your code will never run again, until something explicitly starts up your app (usually the user tapping on your icon in the launcher). There is nothing that you can do about this.
it's hard to explain things when you do understand fully and when english is not your native language
There are many Android developer support sites, offering a variety of languages.
you need to create a service, http://developer.android.com/guide/components/services.html
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 using C2DM in my application, and I have a receiver, which sends data to a class in the application. The class creates a notification and notifies the notification manager to post it.
The problem is that this does not work when the app is forced close manually through the settings, as this also (apparently) shuts off the broadcast receiver.
What I get though is that when an app is shut off with android 4.0's new task manager (the one thats similar to 3.0 but a user can also swipe an app to the left or right to shut it off) it behaves differently: the broadcast receiver is still working, as I get the intent from the C2DM message, but for some reason my phone still plays the notification noise, whilst no notification appears in the tray.
I can't figure out what's happening, because there is no way for the sound to play without the notification to appear, as the sound is attached to the notification and plays when it's posted, no other way. But no notification appears.
Any insight on why this might be happening would be awesome, or what the new 4.0 task manager actually does to apps when you swipe them off the list.
Thanks.
Figured it out, the broadcast receiver was still responding but just failing because it was retrieving things from a class that was part of the main app and was now dead, so now the things it needs are stored in sharedprefs, and retrieved before the notification gets sent.
So to answer the question, no swiping an app from the task manager in 4.0 does not "force kill" the app in the same was as the force kill button in the applications menu in settings. It does kill off the app in such that next time you open it, all the activities restart from scratch, just like if you had been in the last remaining activity and pressed back, hereby calling finish() on the last alive task and shutting down the app. broadcast revivers (and services i assume) still are running afterwards.