Handling of registrationId when the model of Android device changes

Question: Question:

I am creating an Android application using GCM, and for sending push notifications, I have acquired the registrationId with the code below and saved it in Shared Preferences.

registrationId = gcm.register("xxxxx");

When transferring application data using a backup tool, such as when changing models, the registrationId saved in Shared Preferences will also be transferred.

However, with the registrationId (obtained before the model change), push notifications cannot be sent to new terminals.

What should I do in such a case?

From Android M, I think there is a way to exclude specific data from data transfer by using "full-backup-content" tag and "exclude" tag, but since targetSDKversion 23 or higher is the target, in the case of earlier versions What is the best way to deal with it?

Answer: Answer:

Perhaps the situation has changed from the beginning of the question, but I will quote from https://firebase.google.com/docs/cloud-messaging/android/legacy-regid?hl=ja .

Client App Update: An existing registration ID when updating a client app
Is not guaranteed to work with newer versions, so its ID must be disabled. The recommended method is the registration ID
Is to store the current app version when saving and compare this saved value with the current app version when the client app is launched. If they do not match, the saved data will be invalidated and the registration process will start again.

Backup and Restore: Do not save your registration ID when backing up your client app. The registration ID does not always remain valid until the client app is restored, and if the registration ID is invalid, the client app will also be invalid (that is, the app will recognize it as registered). However, in GCM, its registration ID
Will not be saved, so the app will not get the message). The recommended way is to start the registration process, like when the app is installed for the first time.

Therefore, the registrationId acquired before the model change may become invalid, so let's acquire and re-register the registrationId after the model change.

Scroll to Top