0

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.

  1. Is this the correct approach or is there any other way in firebase to store data?
  2. 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>>");
    
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
Hary
  • 5,690
  • 7
  • 42
  • 79

1 Answers1

2

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.

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • Thanks! That meant Users is the collection name or database name? What if I need to create new collection like UserPreferences? – Hary Feb 08 '18 at 09:58
  • 1
    if you want u can call it collection name but its not the database name. It is usually just called "Child node" . You can create another child node normally as for the Users so like this `DatabseReference ref=database.getReference().child("UserPreferences");` If you want to have a nested child then you do like this `DatabseReference ref=database.getReference().child("UserPreferences").child("nestedchild");` – Peter Haddad Feb 08 '18 at 09:59
  • 1
    Thank you got it! Have to wait for 2mins to accept :) – Hary Feb 08 '18 at 10:02
  • 1
    the database name is usually like this `https://test-xxxx.firebaseio.com/`, but you do not need to write it inside the `getReference()` – Peter Haddad Feb 08 '18 at 10:08