title: In GoogleCloudMessaging API, how to handle the renewal or expiration of registration ID?
body: <p>As the question says that How to find out when does the <a href="http://developer.android.com/google/gcm/gcm.html#arch" rel="nofollow noreferrer">registration ID</a> has become invalid in <a href="http://developer.android.com/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html" rel="nofollow noreferrer">GoogleCloudMessaging</a> API?
  I already read the answers on few questions on similar topic: <a href="https://stackoverflow.com/questions/11590482/do-gcm-registration-ids-expire">Do GCM registration id&#39;s expire?</a> and <a href="https://stackoverflow.com/questions/12824924/google-coud-mesaging-gcm-and-registration-id-expiry-how-will-i-know?lq=1">Google Coud Mesaging (GCM) and registration_id expiry, how will I know?</a> . The issue with those question is that the answers there are for <code>C2DM</code>or old GCM API which used <a href="http://developer.android.com/reference/com/google/android/gcm/GCMRegistrar.html" rel="nofollow noreferrer">GCMRegistrar</a> instead of GoogleCloudMessaging API. The previous two methods have been depreciated. </p>
  
  <p>I'll try to <strong>break my confusion/question stepwise</strong>:   </p>
  
  <p><strong>1)</strong> Under the heading <a href="http://developer.android.com/google/gcm/gcm.html#arch" rel="nofollow noreferrer">Enable GCM</a>, in the second point it says:</p>
  
  <p><code>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.</code></p>
  
  <p><code>The registration ID lasts until the Android application explicitly unregisters itself, or until Google refreshes the registration ID for your Android application. Whenever the application receives a com.google.android.c2dm.intent.REGISTRATION intent with a registration_id extra, it should save the ID for future use, pass it to the 3rd-party server to complete the registration, and keep track of whether the server completed the registration. If the server fails to complete the registration, it should try again or unregister from GCM.</code></p>
  
  <p><strong>2)</strong> Now, if that's the case then I should handle the intent in a BroadcastReceiver and send the <a href="http://developer.android.com/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#register%28java.lang.String...%29" rel="nofollow noreferrer">register()</a> request again to get a new registration ID. But the issue is that on the same page under heading  <a href="http://developer.android.com/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#ERROR_MAIN_THREAD" rel="nofollow noreferrer">ERROR_MAIN_THREAD</a>, it says that: 
  <code>GCM methods are blocking. You should not run them in the main thread or in broadcast receivers</code>. </p>
  
  <p><strong>3)</strong> I also understand that there are other two scenarios when the registration ID changes( as mentioned under Advanced Topics under heading <a href="http://developer.android.com/google/gcm/adv.html#reg-state" rel="nofollow noreferrer">Keeping the Registration State in Sync</a>):
  Application update and Backup&amp;restore. I am already handling them on opening of the app.</p>
  
  <p><strong>4)</strong> In GCMRegistrar API, inside <a href="http://developer.android.com/reference/com/google/android/gcm/GCMBaseIntentService.html" rel="nofollow noreferrer">GCMBaseIntentService</a>, there used to be a callback  <a href="http://developer.android.com/reference/com/google/android/gcm/GCMBaseIntentService.html#onRegistered%28android.content.Context,%20java.lang.String%29" rel="nofollow noreferrer">onRegistered()</a> method, which got called when the device got registered. Here I used to persist the registration ID and send to 3rd party servers. </p>
  
  <p>But, now How should I handle the updation or renewal of the registration ID, persist it and send it to 3rd party server?  </p>
  
  <p>It might be that either I am getting confused by reading all of it or I am missing something. I would be really thankful for your help. </p>
  
  <p><strong>Update</strong></p>
  
  <p>Even on <a href="https://stackoverflow.com/questions/16838654/handling-registration-id-changes-in-google-cloud-messaging-on-android">Handling registration ID changes in Google Cloud Messaging on Android</a> thread, there is no mentioning of how to handle the periodic refreshing of ID by Google? </p>