I am using local notification plugin in my application. Here i set notification like alarm. Its working fine. what ever time i set in my database, alarms are working fine.
But while i force stop the application(Setting->Applications->Manage applications->MyApplication->ForceStop), next alarm is not coming. any one can help me?.. i tried with following link,
http://www.javacodegeeks.com/2012/05/android-broadcast-receiver-change-in.html
but still is not working.
force stop app will remove alarm associated with the app
so your pending task will never be done.
read in details:
http://blog.csdn.net/gemmem/article/details/8858461
Related
I searched a lot, but couldn't find nothing clear. Every solution seems outdated. In my app, I need this simple task: the user can enable a daily reminder and select a time in the Time Picker.
Everyday in the selected hour the user should receive a simple notification. I only need to read the local database (Room, SQLite) and then show a notification.
I'm using AlarmManager, because the user should receive the notification in the exact time he selected.
Everthing is working fine when the app is open or minimized. When I close the app in the recently used apps (swipe up) I don't receive the notification.
I have a class that creates the alarm with this calling:
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(), pendingIntent);
The pendingIntent opens a NotificationReceiver extends BroadcastReceiver class. In the onReceive method I read the db and show the notification. I also tried starting a service in the onReceive method (IntentService or Service) but they work exactly as just using the broadcast receiver.
I put the receiver in the AndroidManifest. Everything is working except when I close the app or restart the system (I registred the BOOT_COMPLETED in the manifest and I have another broadcast receiver that configure the alarm again. If I open the app and keep it open before the notification time, then I receive it. But if the app is still closed, I don't receive it. So I thik the BOOT_COMPLETED is working fine).
The other solutions doesn't seem to work. What can I do to have it working on Android 11 (Pixel 3 device)?
One example of what I need is the Google Keep app, but mine is simpler. I don't see any notification dot telling that the Google Keep is running in background. Still, I get the reminders on time. How the Google Keep works? It's a service always running (and killing the battery)? It uses AlarmManager and BroadcastReceiver? WorkManager? Even if a close the app or restart the phone, I always get the notifications. How can I achieve it on my app?
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.
Here is my issue: Let's consider for example that I have a function that schedules a notification every week. So five weeks after having installed my app, I would have had 5 notifications that would have been displayed (one every week). Then, I restart my phone (for whatever reason) and all the notifications that had been displayed during those five weeks appear all in once. I don't understand how come that the previous scheduled notifications appear all in once when I restart my phone? (By the way, I cancel those notifications after they have been displayed). This problem only appears on ANDROID, the same app on IOS works perfectly. So, how come those notifications appear? It's like they are never completely cancelled? I tried several variants to avoid this problem but it doesn't want to go away. Any ideas?
Thanks a lot!
PS: I am using this plugin for local notifications: katzer/cordova-plugin-local-notifications
I have found an answer.
iOS cancels the notifications after they have been triggered. Android does not. Therefore, if the users opens the app, let's say you have scheduled a notification to appear in two days, and then close it and don't reopen it, two days later he will get the notification as scheduled. But, if he never reopens the app, that notification will never be canceled on Android and the notification will re-appear every time you restart your phone. To be cancelled, the user has to reopen the app for the bit of code that you've written to cancel the notification could run. It is very annoying because the purpose of a notification (in my case at least) is to allow the user to get an information without opening the app. Fortunately on iOs, the notifications cancels themselves so it works perfectly.
Thanks to Nic Raboy fr his time and help.
I'm using the ngCordova LocalNotification plugin in my Ionic app and I am trying to get it to repeat but with a random time span.
For example the user will trigger the notification to launch in 1 minute, and after that I would need to have the notification launched again in another 2 minutes (hypothetical example, in real life scenario the time span would be much higher, ie a couple days).
So far I can get the notification to execute for the first time.
Then, I am using the $cordovaLocalNotification:trigger method to detect when the notification was triggered and inside of that method I have a code to schedule a new notification.
All of this works, but in order to launch whatever it is inside of that method's body, I have to acknowledge the notification on my device and click on it, then it launches this method.
So I am wondering if there's a way to have it schedule a new notification without me having to open the previous notification?
All of this has to happen locally on the device and the notification should persist even if the device is rebooted. Thanks a lot!
When the application go in backround, the webview stops the javascript execution. When you click on the notification, the app became a foreground process and javascript continue the execution.
So it seems that it works only when you click on the notification (that open the app) because only when the app is opened, the js code is executed.
You could double check this if you don't click on the notification, opening the app after the notification is displayed (without clicking it).
To clear all the triggered notification you could use the getTriggeredIds(scope) method to get all triggered notification IDs and the clear(ids, scope) method to clear them.
See the localNotification plugin documentation for more information.
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.