Nikunj Acharya
Nikunj Acharya

Reputation: 83

When to generate Registration ID in Google Cloud Messaging

I am working with android app in which i am using GCM. now I don't know when to create new Registration Id for device.? I am saving Registration Id in sharedpreferences. and i know that when app version changes we have to regenerate ID. but when user logout from app, does it necessary to regenerate ID ? Can I use previous Reg Id for that particular user because I am storing it in database. can multiple devices have same Registration IDs?

Upvotes: 0

Views: 277

Answers (3)

Alok Patel
Alok Patel

Reputation: 8032

Get the device ID on following cases.

  1. Lgout/Login(in case of multiple users)
  2. App version change.
  3. OS updates.

Upvotes: 1

Roberto Betancourt
Roberto Betancourt

Reputation: 2515

You should regenerate the registration id on phone reboots, app updates and OS updates. Check this blog post.

Upvotes: 1

Koh
Koh

Reputation: 1570

Hope I'm not intruding on what @iRuth is planning to advise. Here are some things I want to point out:

  1. One registration ID per device is sufficient.
    • If different users can log in from the same device, you could modify the data field in your message to specify the intended user/recipient. Multiple devices cannot have the same registration IDs.
  2. Do not regenerate registration ID after every log out.
    • Persist the registration ID on the client device. Like you said, only app updates and backups merit another gcm.register() call.

Lastly, I am assuming that by database you meant the client device's database. In that case, yes, just use the already existing registration ID. If you meant your server's database, you will always need to maintain a record on your device of the registration ID and its associated app version. Only having it on your server's DB is not advisable as your client device may no longer be reachable via GCM if the app has been updated.

Upvotes: 0

Related Questions