Reputation: 3671
I have implemented push notification on xamarin forms android project using FCM. But when receive a new notification, old notifications are replaced by the new one. This is happening only when the app is in the foreground mode(when app is in open state). No such issues in background state or killed state. Multiple notifications are showing in background state and killed state.
Following is my notification payload, where webContentList
is my message data.
{
"to" : "dmtfiSvBBM0:APA91bFnHkamMSYgxPuiSfdvKnU8hD_mOqrWijnENNgXVSkSgo1ILH3-uKVCU7Ez2PXXOhtDoobIyKBf5UshVfTmvjSqHgXMRTsqguKCSTjIfGnXrVP-_cNFq2sisshZO-BcfkwKTl-I",
"collapse_key" : "type_a",
"notification" : {
"body" : "This is body",
"title": "Tech Team",
"priority":"high",
"content_available":true
},
"data" : {
"webContentList": [
{
"webContentDefinitionId": 818084,
"pageTitle": "CCD Grade 3-4",
"pageKwd": "CCD Grade 3-4",
"pageDesc": "CCD Grade 3-4",
"siteId": 45,
"pageCreatedTime": 1555145959428,
"pageUpdatedDate": 1555927274279,
"modifier": {
"userId": 12944,
"applicationId": 32,
"username": "robert.downey",
"email": "[email protected]",
"firstName": "Robert",
"lastName": "Downey"
},
"creator": {
"userId": 12944,
"applicationId": 32,
"username": "robert.downey",
"email": "[email protected]",
"firstName": "Robert",
"lastName": "Downey"
}
}
]
},
"ttl": 3600
}
I removed the collapse_key
from the payload, but notifications are replacing in foreground mode.
Please suggest a solution for this issue?
Upvotes: 1
Views: 423
Reputation: 240
Do you handle the foreground notification creation by yourself? If so, a classic mistake is to pass the same id over and over again when creating the local notification, for example like this
mNotificationManager.Notify(1, mBuilder.Build());
You need to pass a different ID for each notification
mNotificationManager.Notify(new Random().Next(),mBuilder.Build());
Upvotes: 3