Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FirebaseInstanceId - Unique per Firebase "App" or Android App?

I create a small Android Application which should create unique userIds.

I was thinking about to use FirebaseInstanceId.getId() for that because the documentation says

Returns a stable identifier that uniquely identifies the app instance

But the what does app mean in this context?

Does app mean the "real" Android or iOS App which uses the FirebaseInstanceId? Or does it mean the "Firebase App" or better the Firebase Project?

Can I assume that the generated id is unique in my Firebase Project and can be stored in FirebaseDatabase as userId or should I create a unique userId in another way?

like image 559
StefMa Avatar asked Mar 11 '23 04:03

StefMa


1 Answers

You can infer that the "app" in this case means a particular app installation on a device. Look at the javadocs for FirebaseInstanceId, and take note of the rules for when an instance id can change. Install/uninstall and clearing app data are a result of user behavior against an app on their device. Note that this value can change, and therefore probably isn't appropriate for uses outside of Firebase.

This value is used by Firebase for identifying an app that could receive a cloud message. It does not represent a particular user. A user could have the same APK installed on multiple devices, using a single account to log into each one of them. If you want to send that user a cloud message, which instance of the app should it go to, on which device? You probably want to send to all of them. That's where instance id comes into play. In order to preserve consistent behavior of your app, no matter how many times it's been installed for a user, you need the instance id of each unique installation in order to target a message to all of them.

To identify a particular user, you should use Firebase Authentication, and assume that they're going to log into the same account every time, so there will be a single UID that you can store to refer to that one person. It's common to associate multiple instance ids to a single user, for the purpose of targeted messaging to that user.

like image 168
Doug Stevenson Avatar answered Apr 29 '23 19:04

Doug Stevenson