I'm using Firebase Cloud Messaging to deliver data messages to an application that i'm developing. According to FCM Documentation, when the app is in foreground:
A client app receives a data message in onMessageReceived() and can handle the key-value pairs accordingly.
and it works fine. When app is in background, the behavior is different:
the data payload can be retrieved in the Intent used to launch your activity.
and it doesn't seems to work pretty well. I'm using a "click_action" parameter in the notification JSON, where I specify the name of the intent filter used in the Android Manifest inside the "activity" tag that i want to open. For example, my notification could be:
{
"to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
"notification" : {
"body" : "This is a test",
"title" : "Test",
"click_action" : "com.test.click"
},
"data" : {
"key" : "data"
}
}
And my manifest has this intent-filter, in the "MainActivity":
<intent-filter>
<action android:name="com.test.click" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
When my app is in background and i launch the notification, everything seems to work well: I click the notification and the correct activity is displayed, and the data keys are in the "extras" of the intent received. The problem comes when my app is closed: when i tap on the notification, the app correctly starts and opens the activity with the "com.test.click" intent-filter, but if I try to send another notification, when I tap on it nothing happens, and background notifications doens't work anymore until I restart the app.
To be more clear: notifications work well while my app is in foreground or in background. If my app is closed, the first notification is handled correctly, but every other background notification doesn't work anymore until I restart the app: if i tap a notification, my app shows the last activity watched, as if I selected the app from the "Recent apps" menu. If i close and restart the app, the notifications return to work properly.
Is this a bug of the data-messages in Android, or a FCM issue? Is there a way to solve this issue?
I'm using a Nexus 5 API 23 for testing.