In my app, when a user executes and event, I add a notification to the notification's bar. Tapping that notification works both if the app is in the foreground or if it is backgrounded.
I would like the notification to persist even if the app is terminated (due to memory, etc.). And have the notification tap relaunch the app.
Is that, at all, possible?
I've searched all over and can't find an answer.
I have set my notification flags to Notification.FLAG_NO_CLEAR so the user can't clear it, but upon app termination, the notification gets removed.
You probably want the notification to be managed by a service. Services can be configured to restart automatically on termination.
Related
I'm using Firebase Cloud Messaging for Android. When my app is in the foreground, FCM will invoke onMessageReceived on my app's FirebaseMessagingService subclass.
When my app is in the background, the Android OS will create a default notification entry in the system tray. That notification entry looks pretty good to me; for the notifications I need to send, I don't particularly need to interrupt the user with the notification. The default notification in the system tray is just fine.
My question is, how do I make that "default" notification happen in onMessageReceived when my app is in the foreground? Is there a way to say, "I don't need to intercept this notification; please just do what you'd normally do if I were in the background"?
(Do I have to simulate it by hand with NotificationCompat.Builder? If so, which settings do I need to pass to get default behavior?)
When the app is in the background, your notifications are processed by the Google Services, which takes care of displaying your notifications as required, including the default click action (opening the app) and the notification icon.
When the app is in the foreground, the received messages are processed by the app.
Yes, you will have to mimic the NotificationCompat.Builder to look like default. There is no other way to do this without intercepting with onMessageReceived() callback.
Reference: https://firebase.google.com/docs/cloud-messaging/android/receive
Users might close my application by swiping them from recent apps because they are used to that. In those cases, users don't get notifications about important events and they are complaining about this. How can I restart a force-closed app so that it will continue to receive FCM messages?
FCM messages are supposed to be received in background. A notification should be shown in the device's tray even if you application is not running / suspended.
My app receives FCM and fires local notifications, which open target activities. This works fine if the local notification is clicked when the app is not running.
But, if the local notification is clicked when my app is already running (foreground or background), I don't want to open the target activity but shows an AlertDialog first. So, the activities stack is not changed and the user can continue what he was doing before.
It seems the local notification must have an action, which opens activities. Is there anyway achieve what I wanted above?
I think you have to stop sending push notification when you app is in foreground
check if your app is in foreground or by following this link
check android application is in foreground or not?
check this in firebaseMessegingService class before sending PN and manage alert dialog appearance according that
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.
If my app fires a notification and marks it as non-clearing (i.e. tapping it does not remove it), what will result in the notification being removed?
Would I be right in assuming that if the app is shut down by the memory manager that this will cause the notification will be removed? Or will the notification persist even if the app is recycled?
My app needs to show a persistent notification, and I need to understand whether I can set it up in the app, or if I need to build a service to manage it.
When you start a notification with the FLAG_NO_CLEAR it will persist until you cancel it in the NotificationManager with a call to NotificationManager.cancel(int notificiationId)
I'm not sure what would happen to the notification if your app were uninstalled, although I suspect it would be cleared then too. That said it should be really easy to test. Create an activity that creates a notification. Then close it, kill it, uninstall it, etc... and see what happens.