From 7126776b306948574b89406a656101dd2c7bb8da Mon Sep 17 00:00:00 2001 From: joeykrim Date: Tue, 5 Jan 2021 03:01:34 -0800 Subject: [PATCH] Updated comments for more clarity on when onNewToken is called (#1242) Given the lengthy history of obtaining the token from C2DM, GCM, FCM, and the transition from InstanceID to Installation SDK, added additional clarity to outline all the known scenarios onNewToken is called to match with the details from https://firebase.google.com/docs/cloud-messaging/android/client#sample-register --- .../fcm/java/MyFirebaseMessagingService.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/messaging/app/src/main/java/com/google/firebase/quickstart/fcm/java/MyFirebaseMessagingService.java b/messaging/app/src/main/java/com/google/firebase/quickstart/fcm/java/MyFirebaseMessagingService.java index f6fd0cde7..3f46dcf86 100644 --- a/messaging/app/src/main/java/com/google/firebase/quickstart/fcm/java/MyFirebaseMessagingService.java +++ b/messaging/app/src/main/java/com/google/firebase/quickstart/fcm/java/MyFirebaseMessagingService.java @@ -104,10 +104,13 @@ public void onMessageReceived(RemoteMessage remoteMessage) { // [START on_new_token] /** - * Called if FCM registration token is updated. This may occur if the security of - * the previous token had been compromised. Note that this is called when the - * FCM registration token is initially generated so this is where you would retrieve - * the token. + * There are two scenarios when onNewToken is called: + * 1) When a new token is generated on initial app startup + * 2) Whenever an existing token is changed + * Under #2, there are three scenarios when the existing token is changed: + * A) App is restored to a new device + * B) User uninstalls/reinstalls the app + * C) User clears app data */ @Override public void onNewToken(String token) {