Reputation: 655
I am developing Android App with GCM.
I get registrationId for sending push notification by the following code and then store it in SharedPreferences.
registrationId = gcm.register("xxxxx");
When my app is transferred from a device to another by backup tool, I guess every data which stored in SharedPreferences are transferred.
Then I think above registrationId is not active in the new device.
Is it true?
If true, what is the best way to solve this problem?
Should I always get the latest registrationId, and then if it is different from the one stored in SharedPreferences, resave the new one?
Upvotes: 0
Views: 153
Reputation: 326
Yes It is true. "For apps that use Google Cloud Messaging (GCM) for push notifications, backing up the registration token that Google Cloud Messaging registration returned can cause unexpected behavior in notifications for the restored app. This is because when a user installs your app on a new device, the app must query the GCM API for a new registration token. If the old registration is present, because the system had backed it up and restored it, the app doesn't seek the new token. To prevent this issue from arising, exclude the registration token from the set of backed-up files." -Taken from developers.android.com
Upvotes: 1