I have managed to do an implementation that allows me to create a device group, add and remove registration ids from it and send messages to it, but now I have come to realize I don't understand when should I be calling this methods.
What I initially thought was
- Create a device group when a user registers to the app
- Add a registration id to the device group on user login
- Remove the registration id I added on login when the user logs out
The problem with this is that if the user was logged to the app in only one device and he logs out then when I remove the registration id the device group will be deleted. This means I won't be able to notify the user of anything until he login again. But this shouldn't be how it works, for example in Facebook even if you are not logged once you enter you get the old notifications.
But the problem if I don't remove the registration ids on logout is that two device groups can have the same registration is inside. When my app gets installed in a phone (in the case Android) it generates a registration id, so far for what I could debug that is the only time it generates one. This means that if a user logs in, logs out and then a new user logs in I could have add that registration id to both users device groups. Does this mean that they will both receive notifications?
I can force to generate a new token when on an user login by doing what is explained here, but I guess there has to be something better than this work-around.
Plus, at some point I need to remove registration ids, otherwise I will reach the 20 limit.
So my question is what is the correct (or a correct) life-cycle for device groups that takes into account the problems I have described and any other I haven't find out yet. Thanks!
Extra question: if I send a notification to a device group and then, before receiving the notification, the user logs in in a new device and I add its registration id to the device group, will it receive the notification? I guess he wouldn't.