Is it possible to receive FCM push notification when app is killed?
There are 2 types of push notifications: Data messages and Notification messages.
If you are using the Data messages you will be in charge of handling the received message and present a notification to the user (if needed of course). But in this case you might miss notifications when your app is closed.
If you are using Notification Messages, FCM is handling the message for you and directly displays a notification if the app is in background/closed.
Please see more here.
It is not possible to receive a push notification in an app that has been killed/stopped by "Force stop" in application settings:
Let me quote the response I got from Firebase Support when I posed them that question:
The Android framework advises that apps that have been stopped (i.e. killed/force-stopped from Settings) should not be started without explicit user interaction. FCM follows this recommendation, and thus does not deliver messages to stopped apps. Here are some documentation that discuss this topic:
- Life of a message from FCM to the device Using Firebase Cloud
- Messaging with Android O
This confirms what I observed when I tested it using a simple app.
But you should be able to get push messages from FCM when the app is in background, even if it was swiped off from Recents screen, or after system reboot. That is, unless the manufacturer made the swipe gesture to work the way "Force stop" does on your device. How you receive it in the background depends on whether the push notification contains the "notification"
payload:
- If it does, you will receive the
"data"
only if user taps on the notification and it will be delivered in theIntent
extras to the activity launched by the notification action. - If it doesn't, you will receive the notification in
onMessageReceived
just like you do when the app is in foreground.