Marcos Miguez Marcos Miguez - 1 month ago 19
Android Question

Firebase Cloud Messaging: best practice

I'm migrating to Firebase Cloud Messaging, and I have one doubt.
My application must show the login screen when launching, and if the user performs login in another account, I must stop send notifications for the older user.


  • What's the best way to do that?

  • Can I force the application to renew the token?

  • Or should I update the token's owner in my base by my own?


Answer

Inside application You should renew Instance ID token and forget about the old one if You don't want to get notifications being sent to the old token. On every logout and login just take new Instance ID and update Your external database (in case Your application logic need it) with information about new token being assigned to that user :) There are no limits for generating new tokens and You cannot reuse once dropped tokens.

Renewing token is just calling getToken() again.

This is the best approach because InstanceID is in fact assigned to the "application instance" so in case of app reinstall on device or removing cache by user You'll have to get new token anyway.

Comments