2

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).

AL.
  • 36,815
  • 10
  • 142
  • 281
Marc DiNino
  • 772
  • 2
  • 6
  • 13
  • Is my understanding correct that your app contains a service invoked periodically by the AlarmManager and you know that service is running after an app version update because you see the "locally scheduled notifications"? – Bob Snyder Feb 06 '17 at 21:01
  • That's correct. To me it seems like this *should" trigger the FCM token to be generated on app update. But I wanted to get other people's thoughts. – Marc DiNino Feb 07 '17 at 00:12
  • I've seen SO posts indicating alarms are cleared when an app is updated. I'm curious how your app's alarms are retained after update. Also, is your app updated from the Play Store or some other source? Finally, are you able to reproduce the behavior on a test device? – Bob Snyder Feb 07 '17 at 15:07

1 Answers1

1

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
Bob Snyder
  • 37,759
  • 6
  • 111
  • 158