Reputation: 2331
I just started to use Google Cloud Messaging and read about User Notifications. According to this link, all the devices owned by a particular user will be notified at once.
In my case, a particular user is identified by his/her user_id and the database would look like this:
[user_id] [gcm_registration_id]
As per the demo, on the application side this registration_id is stored as persistent data.
What happens if the user uninstalls the app and the persistent data is gone?
Will I get the same Registration ID for the same App on the same device once the user re-installs the app?
Will Google invalidate these Registration IDs after some time?
Upvotes: 2
Views: 487
Reputation: 394156
Actually the answer you accepted is not entirely correct.
I tested the case of un-installing and re-installing an app on a device, and in some cases you could get a different registration ID.
There are two cases :
NotRegistered
error from GCM (I believe you'll get that error only from the 2nd message you send).Upvotes: 1
Reputation: 83048
will I get the same registration_id for the same app on the same device once the user reinstalls the app?
YES. Reg id chnages in two cases. Either your app will register OR Google refreshes the Registration ID. SO until any one cases executes your are fine with old reg id.
By any chance google invalidates these registration_ids after some time?
YES. Google refreshes the registration ID. GCM gives you the idea about handleing of updated registartion ID.
Handle updated id on client side
If the registration is successful, the GCM server broadcasts a com.google.android.c2dm.intent.REGISTRATION
intent which gives the Android application a registration ID.
The Android application should store this ID for later use (for instance, to check on onCreate()
if it is already registered). Note that Google may periodically refresh the registration ID, so you should design your Android application with the understanding that the com.google.android.c2dm.intent.REGISTRATION
intent may be called multiple times. Your Android application needs to be able to respond accordingly.
Upvotes: 1