Bravo Bravo - 1 year ago 126
Android Question

How to launch FCM ID Service only after a particular activity is triggered?

Assume I have a

where user can either register or login with existing credentials. I don't want
to generate a token, unless user is logged in and
of the application is launched.

Thank you

Answer Source

You cannot block FirebaseInstanceIdService.onTokenRefresh() from being called until the user is logged in.

What you could do in your use case is:

  • In FirebaseInstanceIdService.onTokenRefresh() ignore the event if the user is not logged-in
  • When the user log-in check FirebaseInstanceId.getToken() and if != null call onTokenRefresh() (or directly your logic) manually.

In this way you can process the token when the user is logged-in, and if the token is not available (or is rotated) you will receive the onTokenRefresh() event later.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download