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
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 an app that starts when the phone starts. In the app I have an option for the user to stop showing a notification from the app. The notification is related to the boot_complete action (it starts a service). I'm wondering how would I stop the App from starting on boot up if the notification is turn off? I'm thinking on setting a shared preference to "No" if the notification is turned off and then check that on the boot complete broadcast. If the preference is set to "No", then nothing will start if it's set to "Yes" then it will start. Is that the best way of doing it or is there a better way to do it?
Yes this is the best way to do this, just implement it in your BroadcastReceiver. I have implemented this multiple times in my apps, it seems to work well.
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 am trying to create an alarm using AlarmManager it works fine even when device is locked.
But when I kill the application using Settings -> Manege App -> MyApp -> Force Stop then my alarm destroys all the settings.
So please tell me how to save my alarm settings after application is killed even by forced stop and it notifies me on its usual time.
Thanks in advance...
But when I kill the application using Settings -> Manege App -> MyApp
-> Force Stop then my alarm destroys all the settings.
AlaramManager is critical system service that runs all the time. And if your application scheduled something and was killed, then AlarmManager may start application again (via PendingIntent).
Just Check this Answer on StackOverflow.
As of Android 3.1, if a user force closes your application, all alarms will be cancelled and will need to be rescheduled from within your code...
From Android Docs....
Note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGES to all broadcast intents. It does this to prevent broadcasts from background services from inadvertently or unnecessarily launching components of stoppped applications. A background service or application can override this behavior by adding the FLAG_INCLUDE_STOPPED_PACKAGES flag to broadcast intents that should be allowed to activate stopped applications.
Applications are in a stopped state when they are first installed but are not yet launched and when they are manually stopped by the user (in Manage Applications).
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.