Is it possible to receive FCM push notifications when app is killed?

Viewed 20334

I am developing an e-mail app in which I want that the user will get a push notification as soon as they receive new email. And for that purpose I am using FCM. I have just tried push notifications using FCM by following this link: https://www.youtube.com/watch?v=XijS62iP1Xo&t=6s in order to test what features FCM provides. But the problem I face is that the device receives push notifications when app is either in foreground or background but it won't receive any push notifications when the app is closed (swipe or clear from the task manager). I don't know how to achieve this via FCM? I want to receive push notifications just like the WhatsApp and Facebook apps.

Every kind of help is appreciated. Thanks in advance.

4 Answers

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:

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:

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 the Intent 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.

Some other cases when your app is not killed, but still may not receive push notifications:

If your App is Killed or in background,check for the Payload in your Launching Screen in My case it is MainActivity so in onCreate() Check for Extras:

if (getIntent().getExtras() != null) {
    for (String key : getIntent().getExtras().keySet()) {
        Object value = getIntent().getExtras().get(key);
        Log.d("MainActivity: ", "Key: " + key + " Value: " + value);
    }
}
Related