title: Firebase Cloud Messaging : Expiration of FCM token
body: <p>I understand that the FCM token renews itself if one of the following happens.</p>
  
  <p>-The app deletes Instance ID<br>
  -The app is restored on a new device<br>
  -The user uninstalls/reinstall the app<br>
  -The user clears app data.  </p>
  
  <p>The following can be used at the App side to monitor Token renewal.</p>
  
  <blockquote>
    <p>Monitor token generation</p>
    
    <p>The onTokenRefreshcallback fires whenever a new token is generated, so
    calling getToken in its context ensures that you are accessing a
    current, available registration token. Make sure you have added the
    service to your manifest, then call getToken in the context of
    onTokenRefresh, and log the value as shown:</p>
  </blockquote>
  
  <pre><code>@Override
  public void onTokenRefresh() {
      // Get updated InstanceID token.
      String refreshedToken = FirebaseInstanceId.getInstance().getToken();
      Log.d(TAG, "Refreshed token: " + refreshedToken);
  
      // If you want to send messages to this application instance or
      // manage this apps subscriptions on the server side, send the
      // Instance ID token to your app server.
      sendRegistrationToServer(refreshedToken);
  }
  </code></pre>
  
  <p>My question is, when the app is terminated, the token expires and there is no way for the FCM server to know what the new token is for the device (if exist). So when I send a notification/data message to this device, the server fails to send it to the device as it doesn't know where to send it to (as there is no valid token). How do I make sure that in such situations I can notify the device ? I dont do a customer token generation. So the it seems to refresh the token now and then. How do I increase the validity of my token ?</p>