<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/managing-cloud-messaging-tokens-koqb84jww" -->

---
title: Managing Cloud Messaging Tokens | daily.dev
description: A practical guide to implementing Firebase Cloud Messaging (FCM) registration token management, covering how to generate, retrieve, store, update, and prune...
canonical: https://daily.dev/posts/managing-cloud-messaging-tokens-koqb84jww
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Managing Cloud Messaging Tokens | daily.dev
og:description: A practical guide to implementing Firebase Cloud Messaging (FCM) registration token management, covering how to generate, retrieve, store, update, and prune...
og:url: https://daily.dev/posts/managing-cloud-messaging-tokens-koqb84jww
og:image: https://api.daily.dev/og/posts/koQB84jWw.png
og:image:alt: Managing Cloud Messaging Tokens
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Managing Cloud Messaging Tokens

**[Firebase](https://daily.dev/sources/firebase-blog)** · 9 min read · 0 upvotes · 0 comments

## Summary

A practical guide to implementing Firebase Cloud Messaging (FCM) registration token management, covering how to generate, retrieve, store, update, and prune tokens using Cloud Firestore and Cloud Functions for Firebase. Includes Kotlin/Android code for handling onNewToken(), caching tokens with Shared Preferences, periodic refresh via WorkManager, deleting invalid tokens on UNREGISTERED/INVALID_ARGUMENT errors, and a scheduled Cloud Function that prunes tokens older than 60 days.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://firebase.blog/posts/2023/04/managing-cloud-messaging-tokens>

## Questions this post answers

### How often should I refresh Firebase Cloud Messaging registration tokens?

Refreshing FCM registration tokens once per month strikes a good balance between battery impact and detecting inactive registrations, and there is no benefit to refreshing more often than weekly. A staleness window of about two months is recommended before considering a token expired and safe to prune from storage.

_daily.dev surfaces practical Firebase patterns for developers building reliable push notification systems._

### Which FCM error codes indicate I should delete a registration token?

An UNREGISTERED response (HTTP 404) or an INVALID_ARGUMENT response (HTTP 400) from the FCM HTTP v1 API signals a stale or invalid token that should be deleted from storage. INVALID_ARGUMENT only indicates a bad token when the rest of the message payload is confirmed valid, since that code can also be thrown for payload issues.

_Developers hardening notification delivery pipelines track these error-handling details on daily.dev._

### How do I detect when an FCM registration token changes on Android?

Extend FirebaseMessagingService and override onNewToken(), which fires both when a new token is generated after initial app startup and whenever an existing token changes, such as after app reinstall, cleared app data, device restoration, hardware failures, or FCM forcing a rotation like after a compromised encryption key.

_daily.dev helps mobile developers stay current on FCM token handling patterns while building notification systems._

## Similar posts on daily.dev

- [When Notifications Became Data Trucks: A Real-World Crash Story from Firebase FCM](https://daily.dev/posts/when-notifications-became-data-trucks-a-real-world-crash-story-from-firebase-fcm-nh9ixqylv) · ProAndroidDev · 1 upvotes · 0 comments
- [Using Flutter with Firebase: A Developer's Guide](https://daily.dev/posts/using-flutter-with-firebase-a-developer-s-guide-jbpavk3vl) · Flutter Community · 0 upvotes · 0 comments
- [Securing Your MCP Server with Firebase Auth: A Production Walkthrough](https://daily.dev/posts/securing-your-mcp-server-with-firebase-auth-a-production-walkthrough-kcbboeofo) · ITNEXT · 0 upvotes · 0 comments
- [How to Use Dart Cloud Functions and the Firebase Admin SDK: A Handbook for Developers](https://daily.dev/posts/how-to-use-dart-cloud-functions-and-the-firebase-admin-sdk-a-handbook-for-developers-ailkvowjb) · freeCodeCamp · 2 upvotes · 0 comments
- [An Android auth architecture with encrypted tokens, auto-refresh, and reactive navigation](https://daily.dev/posts/an-android-auth-architecture-with-encrypted-tokens-auto-refresh-and-reactive-navigation-wwm3gd3dy) · ProAndroidDev · 0 upvotes · 0 comments

---

Tags: [#android](https://daily.dev/tags/android), [#firebase](https://daily.dev/tags/firebase), [#gcp-cloud-functions](https://daily.dev/tags/gcp-cloud-functions)

[View this post on daily.dev](https://daily.dev/posts/managing-cloud-messaging-tokens-koqb84jww)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Managing Cloud Messaging Tokens","url":"https://daily.dev/posts/managing-cloud-messaging-tokens-koqb84jww","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/managing-cloud-messaging-tokens-koqb84jww"},"datePublished":"2026-08-23T12:21:14.650Z","dateModified":"2026-08-23T12:46:03.966Z","description":"A practical guide to implementing Firebase Cloud Messaging (FCM) registration token management, covering how to generate, retrieve, store, update, and prune...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7ed721de96163685d26ab7e314be3ebc?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7ed721de96163685d26ab7e314be3ebc?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Firebase","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Firebase","logo":"https://media.daily.dev/image/upload/s--i395oqZH--/f_auto,q_auto/v1787487448/logos/firebase-blog?_a=BAMAMicg0","url":"https://daily.dev/sources/firebase-blog"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/managing-cloud-messaging-tokens-koqb84jww","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"android,firebase,gcp-cloud-functions","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Firebase","item":"https://daily.dev/sources/firebase-blog"},{"@type":"ListItem","position":3,"name":"Managing Cloud Messaging Tokens"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/managing-cloud-messaging-tokens-koqb84jww#faq","mainEntity":[{"@type":"Question","name":"How often should I refresh Firebase Cloud Messaging registration tokens?","acceptedAnswer":{"@type":"Answer","text":"Refreshing FCM registration tokens once per month strikes a good balance between battery impact and detecting inactive registrations, and there is no benefit to refreshing more often than weekly. A staleness window of about two months is recommended before considering a token expired and safe to prune from storage. daily.dev surfaces practical Firebase patterns for developers building reliable push notification systems."}},{"@type":"Question","name":"Which FCM error codes indicate I should delete a registration token?","acceptedAnswer":{"@type":"Answer","text":"An UNREGISTERED response (HTTP 404) or an INVALID_ARGUMENT response (HTTP 400) from the FCM HTTP v1 API signals a stale or invalid token that should be deleted from storage. INVALID_ARGUMENT only indicates a bad token when the rest of the message payload is confirmed valid, since that code can also be thrown for payload issues. Developers hardening notification delivery pipelines track these error-handling details on daily.dev."}},{"@type":"Question","name":"How do I detect when an FCM registration token changes on Android?","acceptedAnswer":{"@type":"Answer","text":"Extend FirebaseMessagingService and override onNewToken(), which fires both when a new token is generated after initial app startup and whenever an existing token changes, such as after app reinstall, cleared app data, device restoration, hardware failures, or FCM forcing a rotation like after a compromised encryption key. daily.dev helps mobile developers stay current on FCM token handling patterns while building notification systems."}}]}
```

