Registration Token is a unique device identifier that Firebase Cloud Messaging (FCM) uses to deliver push notifications. Each app on each device receives its own token, without which sending notifications is impossible. According to Firebase, 2025, the Registration Token is automatically generated when the app is first launched and may change under certain conditions.
Key Takeaways
Registration Token is a unique string up to 4096 characters long that Firebase Cloud Messaging assigns to each app instance. The token is formed based on the application ID, device ID, and the Google account on the device.
A Registration Token consists of a random sequence of characters encoded in Base64 format. FCM uses this token as a delivery address — the server sends a notification to the token, and FCM routes it to the specific device. Without a token, it is impossible to address a push notification to a specific user.
A Registration Token should not be confused with a Device ID (IMEI) or Advertising ID. Device ID is a hardware identifier of the device, while Advertising ID is used for advertising purposes. Registration Token is tied to the combination of app and device, and one device can have multiple tokens for different apps.
| Identifier | Purpose | Mutability |
|---|---|---|
| Registration Token | FCM push notification delivery | May change |
| Device ID (IMEI) | Hardware identification | Permanent |
| Advertising ID | Targeted advertising | Can be reset |
| Instance ID | Legacy Firebase mechanism | Changed on deletion |
FCM may consider a Registration Token invalid in several situations. If the app is removed from the device, the token is automatically revoked. When restoring data from a backup on a new device, the old token stops working. Firebase also returns a UNREGISTERED status when attempting to send a notification to an outdated token.
Firebase Cloud Messaging generates a Registration Token when the app is first launched and the getToken() method is called. The process includes verifying Google Play Services credentials and registering the app in the Firebase infrastructure.
When a device runs an app with the integrated FCM SDK for the first time, the following occurs. The Firebase SDK checks for Google Play Services on the device. The SDK then sends a request to Firebase servers, passing the application ID and device information. The Firebase server creates a new token and returns it to the app.
FCM uses an architecture based on long-lived connections. After receiving a Registration Token, the device establishes a persistent connection to Firebase servers via the STOMP protocol on Android or the APNs channel on iOS. When the server sends a notification to the token, FCM finds the device by the token and delivers the payload.
A Registration Token may be regenerated by FCM in the following cases. When restoring an app from a backup on a new device. When deleting and reinstalling the app. When clearing app data through system settings. When signing into a different Google account on the device. Firebase recommends always handling the onNewToken callback to track changes.
On Android, the Registration Token is obtained through the Firebase Messaging SDK. The process differs for different SDK versions — newer versions use the FirebaseInstallations API instead of the deprecated FirebaseInstanceId.
Starting with Firebase SDK version 21.0.0, the getToken() method is called through FirebaseMessaging. This approach automatically manages the token lifecycle and subscribes to its updates.
class MyFirebaseMessagingService : FirebaseMessagingService() {
override fun onNewToken(token: String) {
sendRegistrationToServer(token)
}
private fun sendRegistrationToServer(token: String) {
// Sending token to server
Log.d("FCM", "New token: $token")
}
init {
FirebaseMessaging.getInstance()
.getToken()
.addOnCompleteListener { task ->
if (!task.isSuccessful) {
Log.w("FCM", "Fetching FCM token failed")
return@addOnCompleteListener
}
val token = task.result
sendRegistrationToServer(token)
}
}
}
In some scenarios, the token is needed not in the service but directly in an Activity or ViewModel. In this case, getToken() can be called at a convenient point in the app lifecycle. It is important not to call this method from the main thread without handling asynchrony.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
getFCMToken()
}
private fun getFCMToken() {
FirebaseMessaging.getInstance().getToken()
.addOnCompleteListener { task ->
if (task.isSuccessful) {
val token = task.result
Log.d("FCM", "Token: $token")
}
}
}
}
In older versions of the Firebase SDK (before version 20.x), the token was obtained via FirebaseInstanceId.getInstance().getToken(). This method is marked as deprecated and is not recommended for use in new projects. Developers maintaining legacy code should migrate to the FirebaseInstallations API.
On iOS, the process of obtaining a Registration Token differs architecturally — FCM works through the Apple Push Notification service (APNs). The Firebase SDK receives a unique device token from APNs, converts it to FCM format, and passes it to the app.
To use FCM on iOS, you must configure an APNs certificate or key in the Firebase console. The app must request notification permission via UNUserNotificationCenter. After receiving the APNs token, the Firebase SDK automatically generates the Registration Token.
import FirebaseMessaging
import UserNotifications
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
application: UIApplication,
didFinishLaunchingWithOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
Messaging.messaging().delegate = self
requestNotificationAuthorization()
return true
}
private func requestNotificationAuthorization() {
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound, .badge])
}
}
extension AppDelegate: MessagingDelegate {
func messaging(
messaging: Messaging,
didReceiveRegistrationToken fcmToken: String?
) {
Log.d("FCM", "Token: \(fcmToken ?? "")")
sendTokenToServer(token: fcmToken)
}
}
The Registration Token on iOS is smaller compared to the Android token, as it is based on the APNs device token. The Firebase SDK automatically updates the FCM token when the APNs token changes, which happens when restoring a device from a backup or reinstalling the app.
Managing the lifecycle of a Registration Token is critically important for reliable push notification delivery. If the server stores an outdated token, notifications will not be delivered, and Firebase will return a UNREGISTERED error.
The Firebase SDK provides two mechanisms for tracking token changes. On Android, the onNewToken callback in FirebaseMessagingService is used. On iOS, the messaging:didReceiveRegistrationToken delegate is used. Both are called each time the token is updated.
// Saving token to SharedPreferences and sending to server
class TokenManager(private val context: Context) {
companion object {
private const val PREFS_TOKEN_KEY = "fcm_registration_token"
}
fun saveToken(token: String) {
val prefs = PreferenceManager
.getDefaultSharedPreferences(context)
prefs.edit().putString(PREFS_TOKEN_KEY, token).apply()
}
fun getSavedToken(): String? {
val prefs = PreferenceManager
.getDefaultSharedPreferences(context)
return prefs.getString(PREFS_TOKEN_KEY, null)
}
}
The server must store the Registration Token in association with the user identifier. When the token is updated, the client sends the new token to the server, and the server replaces the old one. It is recommended to keep a token history: if a notification is not delivered to the new token, the old one can be tried.
Firebase may return a token retrieval error in several cases. If Google Play Services are missing on the device, the token will not be obtained. If the request quota to FCM is exceeded, an exponential backoff should be implemented for retries. If the token expires, the SDK automatically requests a new one.
| Situation | Result | Developer Action |
|---|---|---|
| App removal | Token is revoked | Delete token from database |
| Backup restoration | New token | Update in database |
| Google Play Services reset | Token regenerated | Handle onNewToken |
| Token expiration | Automatic update | Subscribe to updates |
Frequently Asked Questions
Check that Google Play Services is available on the device, verify the google-services.json file, and check the Firebase SDK version. Make sure the app has internet permission.
The token may change when uninstalling and reinstalling the app, clearing data, restoring from a backup, or signing into a different Google account. There is no fixed time interval.
Yes, each app on the device receives its own FCM token. If a device has three apps with Firebase, each will have its own unique Registration Token.
Send a test notification through the Firebase console or the FCM HTTP API. If the token is invalid, the API will return a UNREGISTERED or NOT_FOUND error.
A Registration Token is not a secret key, but its leak allows sending notifications to the user's device. Store tokens in a secure database and use HTTPS for transmission.
Summary
We will develop a mobile application turnkey
IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.
Read also