1

okay, I just want to make sure, is FCM onMessageReceived won't be called when app quit (not in background) ?

My notification work when both app is running and app is in background, but it's not work when app quit(swipe form running apps).

{
"data": {
    "title": "Title",
    "body": "Body",
    "icon": "myicon",
    "priority": "high"
},
"notification": {
    "title": "Title",
    "body": "Body",
    "icon": "myicon",
    "priority": "high"
},
"registration_ids": [some_ids]
}
Lyan Dwi Pangestu
  • 463
  • 1
  • 7
  • 23
  • 1
    Notifications messages will be delivered to your app's `onMessageReceived()` when your app is in the foreground. When the app is not in the foreground, Firebase Cloud Messaging automatically displays the messages. See [the Firebase documentation](https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages) and [this previous question](http://stackoverflow.com/questions/37711082/how-to-handle-notification-when-app-in-background-in-firebase). – Frank van Puffelen Aug 13 '16 at 16:34
  • I have updated my question with my json data that will send to Firebase API. is it a wrong json format to make Firebase Cloud Messaging automatically displays the messages like you said ? – Lyan Dwi Pangestu Aug 14 '16 at 00:25
  • Normally, even that you use both message types together(notification and data), it acts like you are using notification type message and doesn't trigger you when app is background, so propose is to only use "data" messages if your app aims to use the message content in background application. – Hayra Jan 17 '18 at 19:57

2 Answers2

1

There are two types of fcm messages - Data messages and Notification messages.

Data messages(contains data paylaods) are handled in onMessageReceived whether the app is in the foreground or background.

Notification messages are only received in onMessageReceived when the app is in the foreground.

Messages containing both notification and data payloads are treated as notification messages. They will be automatically delivered on system tray by the system.

Akash Bisariya
  • 3,855
  • 2
  • 30
  • 42
0

There is no issue, because fcm service itself in background, after swipe from running apps, you just wifi disable/enabled then your fcm will work

You will get notifications,just i check working as per expectations

Yogesh Rathi
  • 6,331
  • 4
  • 51
  • 81
  • I have updated my question with my json data that will send to Firebase API. is it a wrong json format to make Firebase Cloud Messaging automatically displays the messages ? – Lyan Dwi Pangestu Aug 14 '16 at 00:27