问题
I have integrated Firebase Authentication with Android App. Now I have to store other app related data like user extended profile, user preferences, settings etc.
According to Firebase documentation, Realtime database can be used to save any data.
- Is this the correct approach or is there any other way in firebase to store data?
If this is the correct approach, what database name should I use here? I meant where to create the database in Firebase?
FirebaseDatabase database = FirebaseDatabase.getInstance(); DatabaseReference myRef = database.getReference("<<Database Name>>");
回答1:
Yes, this is the correct approach. If you are using firebase authentication to sign in a user using email for example, then you have to use firebase realtime database to be able to store other information related to the user example:
Users
userid
name:userx
email: userx@gmail.com
age: 102
userid1
name: usery
email:usery@gmail.com
age: 200
To be able access the instance of the database with child node Users you can do this:
DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child("Users");
Or this:
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabseReference ref=database.getReference().child("Users");
No need to write the name of the database inside the getReference("<name here>");
. This was needed in the old versions but it is not needed now.
来源:https://stackoverflow.com/questions/48682346/how-to-store-data-in-firebase-along-with-authentication-data