There are some reasons for this issue and sometimes its depends on device
CM having two ways to send notifications
Data messages
{
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"data":{
"Nick" : "Mario",
"body" : "great match!",
"Room" : "PortugalVSDenmark"
}
}
}
|
it will trigger the FirebaseMessagingService onMessageReceived method.
it will not work on some devices, when an app is in the background.
Notification Messages
{
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification":{
"title":"Portugal vs. Denmark",
"body":"great match!"
}
}
}
|
Notification messages are delivered to the system notification tray when the app is in the background.
For apps in the foreground, messages are handled by a callback function
onMessageReceived method of your FirebaseMessagingService
To avoid the issue of not receving messages
add below code in manifest file
<service
android:name="com.yourapp.SERVICE"
android:stopWithTask="false" />
|
If we set to true, this service with be automatically stopped when the user remove a task rooted in an activity owned by the application. The default is false.
If the flag is false, there is an onTaskRemoved callback in your Service class.
In this case you can detect the onTaskRemoved on "swipe" event and you can again start the FirebaseMessagingService