user6597752
user6597752

Reputation: 190

FirebaseInstanceId.getInstance().getToken() reliability

As I read from documentation and other sources it is advised to call FirebaseInstanceId.getInstance().getToken(); inside onTokenRefresh() to make sure that we get the updated token

what I tried was to call it every time the app is opened and its returning value always, and I am wondering is that a thing to trust ?(is it guaranteed to generate the token every time its called? ) or is there any case it might return null ?

since I don't want users logged in to multiple devices with the same account I am hoping to use it as unique identifier.

Upvotes: 0

Views: 414

Answers (1)

AndiM
AndiM

Reputation: 2188

As per my knowledge and experience I will try to resolve your doubts:

Is it guaranteed to generate the token every time its called?

No it will not generate token every time you call this method. It will just return current token.

Is there any case it might return null ?

Yes it returns null if your token is not yet generated.

I am hoping to use it as unique identifier

Yes you can use it as a unique identifier for each device not for each account. Every device has its unique token.

This is from the official doc:

Retrieve the current registration token

When you need to retrieve the current token, call FirebaseInstanceId.getInstance().getToken(). This method returns null if the token has not yet been generated.

For more information refer this link.

Upvotes: 3

Related Questions