0

So I am having a hard time figuring out when the InstanceID is created any why it isn't working upon the first time it is opened.

When I run the app for the first time, this code returns null.

FirebaseInstanceId.getInstance().getToken();

I even tried a while loop and just waited till it returned something but no luck.

BUT when I close the app and open it again, I then get the InstanceID. Any clue why? I'm trying to obtain it on the splash screen of the app.

onTokenRefresh is not being called untill the restart. I can see some work arounds... but prefer to just get it off the bat.

Thanks!

2 Answers2

0

From the documentation:

On initial startup of your app, the FCM SDK generates a registration token for the client app instance. If you want to target single devices or create device groups, you'll need to access this token by extending FirebaseInstanceIdService.

You need to subclass FirebaseInstanceIdService, add that service to your manifest, and override onTokenRefresh() to get notified of any updates to the token.

If FirebaseInstanceId.getInstance().getToken() returns null, that means there's just no token available yet. So you should be waiting for it instead in your service.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Yeah, I got all that. I guess there is no way to call for a generation. I guess my issue is that it is taking too long for it to generate. – Daniel Choi Sep 07 '17 at 23:28
0

Turns out, It washing saving properly rather than it not being created. It was one of those days..