4

I have an android app where i am sending push notifications using FCM(Firebase Cloud Messaging) to my users, now i have a doubt that when a user updates my app then does FCM updates app's register id or not. And if it updates then if i will send push notification to my user to his both old register_id as well as his new_register id then will he receive the same push notification two times or not.

Also if he will receive push notification two times then how can i send only one notification, because when my app gets updated then there is no possible event through which i can tell my server to remove old _register id and add new register_id in my database.

Please help me here i have read many answers but most of them talks about GCM but as now there is only FCM i do not know how to handle all of this using FCM.

Prakash Kumar
  • 829
  • 1
  • 15
  • 32

1 Answers1

3

The FCM system will automatically handle the registration ID change/update and will not send the message twice. There are many reasons why FCM will update a device's registration ID and this ID can update many times without you even updating your app.

I believe the only way to end up getting the same alert twice is if your code is specifically registering the device twice, but if you are following the documentation for getting started you shouldn't have this problem.

I have been using FCM in my app since it came to be, and I have had the registration tokens change/update hundreds upon hundreds of times and none of my devices have ever received any notifications more than once, nor have they ever missed a notification. The FCM system seems to handle the notifications during token changes quite reliably!

My server also does not track whether a device received a notification or not, however, I do have some logic on the device end that updates a key in Firebase Database to indicate if a device has received the notification. I do not, however, use this logic to re-send the notification, I only use it to notify the sender if the notification went through or not.

Update: Just for some extra info, here is a scenario where you will receive two notifications though, so ensure you don't try to implement both GCM and FCM. Firebase send push notification twice

Community
  • 1
  • 1
Ryan
  • 1,988
  • 4
  • 21
  • 34
  • I am asking about if my user update his app not about when FCM update a device's reg_id, i know all cases when FCM update device register id and i am handling all the cases i just want to know when user updates his/her app from play store then will FCM update register id and even if then will i get two notification or not ?? – Prakash Kumar Sep 24 '16 at 17:24
  • Sometimes it will update the ID and sometimes it wont. Most of the version updates to my app that I have pushed have not caused FCM to update. However, sometimes it does, and in those cases, FCM has handled it appropriately. The only way updating your app would cause dual notifications is if you somehow ended up with two instances of your app running, or two of the receivers listening and responding to the incoming FCM. – Ryan Sep 24 '16 at 18:45
  • so that means after updating my app user will get new registration id for my app and now FCM will use this registration id not the old one. am i right ?? – Prakash Kumar Sep 24 '16 at 19:46
  • yes this is correct. And in many cases I have noticed that it doesn't even change the ID during the update. But yes, if it does change, it uses the new token. – Ryan Sep 24 '16 at 20:45