I know that in Android as in iOS and WP7 (In which mobile platforms the “push token” is not permanent?) the push token provided to the device CAN change.
That means we should handle this by requiring a new token ,at least every time our application launches.
However , this comes to complete contradiction to what i 've found so far in googles tutorials.(I cant remember where exactly i 've found this code , but i am pretty sure it was provided by google) The code looks like this :
//registering for push
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, SENDER_ID);
Log.i("****************","I just Registered!!");
} else {
Log.i("****************","Already registered");
}
The code above will execute the GCMRegistrar.register(this, SENDER_ID);
line only once , the first time that the application launches. But i guess this ir wrong right? Because if the token changes , there is not way that our application will see that as it requires a token only once..
EDIT
Actually i just found where exactly was that code. Take a look here : Get Started Guide
I am quoting :
In the onCreate() method, add the following code:
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, SENDER_ID);
} else {
Log.v(TAG, "Already registered");
}
When you register the device , the onRegistered(Context context, String regId):
function is called. About this function the tutorial says :
onRegistered(Context context, String regId): Called after a registration intent is received, passes the registration ID assigned by GCM to that device/application pair as parameter. Typically, you should send the regid to your server so it can use it to send messages to this device.
So it says that i should send this id to my server. But the code before showed us that this function will be called just once ! So what happens when the token changes? How am i going to refresh it , to my server ? I think i should run this function every time the app launches ...
Am i missing something here? Is the code wrong? Any thought would be helpful :)