public class

FirebaseInstanceIdService

extends Service
java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ com.google.firebase.iid.FirebaseInstanceIdService

Class Overview

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>

Summary

[Expand]
Inherited Constants
From class android.app.Service
From class android.content.Context
From interface android.content.ComponentCallbacks2
Public Constructors
FirebaseInstanceIdService()
Public Methods
void onTokenRefresh()
Called when the system determines that the tokens need to be refreshed.
[Expand]
Inherited Methods
From class android.app.Service
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.content.ComponentCallbacks2
From interface android.content.ComponentCallbacks

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.