Android FCM not receiving notifications when app is removed from background

I also faced the same issue.

Two ways to solve this issue

1- Using notification payload

notification payload can be send using data tag or notification tag.

using data tag

 "data" {
  "title": "welcome",
  "description" :"to your app" ,
  "image" :"image_url",  
  "deeplink" :"deeplink",
   - -
  }

it will trigger the FirebaseMessagingService onMessageReceived method. it will not work on some devices, when an app is in the background.

using notification

 "notification" {
   "title":"title",
   "description" : "description",
   "click_action" :"activity to be open"
   ..
}

this is handled android system try and show the notification, this case onMessageReceived method of your FirebaseMessagingService will not call.notification will be shown even app is in the background. one disadvantage of this is - you can't the customize notification because it's handled by the Android system. more info

2- Enable Auto start in device setting

when you send notification using data and app is killed notification will not be shown. if you observe the log cat you will see

W/GCM-DMM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.cabipool (has extras) }

can be solved in oneplus 3 setting -->Apps --> click on gear wheel -->last option App select app auto launch --> find your app enable the switch

this the problem in most of the devices like Vivo,Oppo,xiaomi,Asus, one plus 3.

steps to enable app auto launch very based on device manufacturer.

Update:

OnePlus 3 and Android 8.0 the Auto-start option was removed, so now you can go to Settings> Battery> Battery Optimisation> (Three dots menu on the left-top corner) Advanced optimization> Turn off Advanced Optimization.


This looks like a problem of the specific device.

To check run this command while your app is closed (after a reboot or after swiping)

adb shell dumpsys package MY-PACKAGE | grep stopped

if you can read stopped=true it means that the manufacturer of your device implemented a non standard behavior consisting in "force-stopping" applications when they are swiped.

force-stopping is very similar to disabling the app until the user opens it again.
When the app is in that state many other Android API will not work! (broadcasts, alarms..)

If this is the problem, please please contact the manufacturer and request that they fix the device!