Marc DiNino
Marc DiNino

Reputation: 812

Will an FCM token be generated if the user updates the app but doesn't open it?

Our Android app recently migrated to Firebase. In our server logs, we see that a few users do not have a valid token. We have also determined that these users see locally scheduled notifications, but aren't actually opening the app after upgrade.

So the flow is:

  1. The user has a version of the app that is not using FCM.
  2. The user updates their app to a version that uses FCM, but does NOT open the app.
  3. The user is getting local notifications scheduled from previous activity, but is not opening the app or clicking on those notifications.

My question is: is this just a limitation of onTokenRefresh#FirebaseInstanceIdService, or should we expect a token to be generated somewhere in that flow?

Note that there is an AlarmManager service that runs once every 15 minutes (I'm not sure what that does to the app lifecycle).

Upvotes: 2

Views: 1012

Answers (1)

Bob Snyder
Bob Snyder

Reputation: 38289

I have not been able to reproduce the behavior you describe. You are correct in expecting that execution of any component of your app: Activity, Service, or BroadcastReceiver, will cause Firebase to initialize, including generation of a token. In your case, you report that an app service, invoked by a periodic alarm, runs. That should be enough to trigger generation of the token. My tests (using 10.0.1) confirmed that a token was generated and onTokenRefresh() called for that case.

Any mention of processing not occurring until an app is launched by the user suggests a connection with the app Stopped State. If a user force-stopped your app using Settings > AppManager > (your app) > Force-Stop, and then the app was updated, the app remains in Stopped state and token generation would not occur until the user launched the app. But you report that the alarm service is running, which would not occur if the app was in the Stopped state.

You might consider using a BroadcastReceiver registered in the manifest to receive ACTION_MY_PACKAGE_REPLACED. This action is broadcast when your app is upgraded. Execution of your receiver will cause Firebase initialization and token generation. My test confirmed that.

FWIW, in my tests I used this command to simulate app update:

> adb install -r /path/to/apk/my-test-app.apk

Upvotes: 1

Related Questions