title: Confused about GCM Token updation process
body: <p>Trying to implement google's latest <code>GCM</code> services. I have read <a href="https://developers.google.com/cloud-messaging/android/client" rel="noreferrer">GCM documentation</a>. I have also downloaded &amp; analysed <a href="https://developers.google.com/cloud-messaging/android/start" rel="noreferrer">google's sample implementation</a>. From all the above I understood the following:</p>
  
  <ol>
  <li><code>InstanceId</code> services provide APIs to generate <code>gcm registration tokens</code> You send &amp; store this generated token in your app server.</li>
  <li>These tokens can be changed once in a while from client side as well as instanceId service side as mentioned <a href="https://developers.google.com/cloud-messaging/registration#keeping-the-registration-state-in-sync" rel="noreferrer">here</a>. To handle this, you have to implement <code>InstanceIDListenerService</code> and the InstanceID provider will call  <code>onTokenRefresh</code> where you just write your logic to get a new token and sending it to server (<a href="https://github.com/googlesamples/google-services/blob/master/android/gcm/app/src/main/java/gcm/play/android/samples/com/gcmquickstart/MyInstanceIDListenerService.java" rel="noreferrer">Google's sample app </a>)</li>
  <li>There's something called <code>canonical_id</code> (<a href="https://developers.google.com/cloud-messaging/registration#canonical-ids" rel="noreferrer">as mentioned here</a>) (which is the last registration_id send from a device) that GCM server sends your device if your app server sends an older registration id. You have to replace your existing token in server with this canonical_id.</li>
  </ol>
  
  <p>Now, following are my questions:</p>
  
  <ol>
  <li><code>InstanceId.getToken</code> seems to return same token if the app is not uninstalled and it returns pretty fast if the token hasn't changed. So, can I call the <code>RegistrationIntentService</code> every time I start the app? This way I'm guaranteed to get to work with the latest token all the time.</li>
  <li>How does the <code>onTokenRefresh</code> if refresh happens while your app is not  connected to the play store (no internet or something)? Does <code>InstanceId</code> provider re-try? Is this documented somewhere? What happens if at the same time a push notification is sent? </li>
  <li>What exactly is a <code>canonical_id</code>? is it the latest token generated for a device (initiated by <code>InstanceID.getToken</code> at client or at <code>InstanceId</code> provider end)? If <code>canonical_id</code> is indeed the latest gcm token, what is the need of <code>onTokenRefresh</code> implementation as you can anyway analyse the push notification data and update your app server if you find a <code>canonical_id</code> provided?</li>
  </ol>