I have read articles about GCM may refresh registration id with no regular cycle. I am trying to build an app using push notification but not so sure how to handle such refreshed registration ids.
My first strategy is requesting registration id everytime the app starts and send it to the app server. It looks working but sounds wrong somehow…
Is it ok to do like this?
Basically, you should do the following in your main activity:
Afterwards you should send the registration id to your app server, whenever the app receives an
com.google.android.c2dm.intent.REGISTRATIONintent with aregistration_idextra. This could happen when Google periodically updates the app’s id.You can achieve this by extending
com.google.android.gcm.GCMBaseIntentServicewith your own implementation, e.g.:For more details, I would (re)read the documentation for writing the client side code and the Advanced Section of the GCM documentation.
Hope that helps!