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!
From the documentation:
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.