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

18,266

Solution 1

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.

Solution 2

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:

Share:
18,266
Iqraa
Author by

Iqraa

Updated on June 03, 2022

Comments

  • Iqraa
    Iqraa about 2 years

    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.

  • Xenolion
    Xenolion over 6 years
    You might miss notifications when your app is closed! seriously??
  • Xenolion
    Xenolion over 6 years
    How does that happen I have never seen that??
  • Sagar Panwala
    Sagar Panwala almost 6 years
    @Xenolion : check in 8.0 devices specially Xiomi, Oppo, Vivo, Lenovo. They don't shows up notification, but if you turn off battery optimization notification will shows up. but problem is we can't go to user and tell to do it.
  • Xenolion
    Xenolion almost 6 years
    Is it related to battery optimization OR is it because of not using notification channels? But I think that's not good, they should surely reconsider the design or at least using AI how the user interacts with apps. Because he might miss some notifications in an App like a chatting app!
  • d51
    d51 over 3 years
    I turned off battery optimisation for my app, and now when I swipe out the app I receive the notification!