FirebaseInstanceIdService

public class FirebaseInstanceIdService extends Service

Base class to handle Firebase Instance ID token refresh events.

Any app interested in the Instance ID, or using Instance ID tokens, can extend this class and implement onTokenRefresh() to receive token refresh events.

To enable your FirebaseInstanceIdService include the following code in the manifest:

<!-- FirebaseInstanceIdService performs security checks at runtime,
      no need for explicit permissions despite exported="true"             -->
 <service android:name=".MyFirebaseInstanceIdService" android:exported="true">
     <intent-filter>
         <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
     </intent-filter>
 </service>

Inherited Constant Summary

Public Constructor Summary

Public Method Summary

void
onTokenRefresh()
Called when the system determines that the tokens need to be refreshed.

Inherited Method Summary

Public Constructors

public FirebaseInstanceIdService ()

Public Methods

public void onTokenRefresh ()

Called when the system determines that the tokens need to be refreshed. The application should call getToken() and send the tokens to all application servers.

This will not be called very frequently, it is needed for key rotation and to handle Instance ID changes due to:

  • App deletes Instance ID
  • App is restored on a new device
  • User uninstalls/reinstall the app
  • User clears app data

The system will throttle the refresh event across all devices to avoid overloading application servers with token updates.