How to retrieve data from realtime database in Firebase?

Monahansen :

I am developing an app where the user registers, enters some information and is then redirected to another page where they can see the information they entered. The information is saved in a real time database using firebase and my problem is how to retrieve that data to display? I have looked at tutorials but i do not understand how this data is able to be retrieved in an array list or something like that.

Here is my database structure, where the id is the user's uuid: https://imgur.com/a/orNqyeq

And here is how i save the data to the database:

this is the class constructor that holds the different variables being saved

  public PersonalInfo(String Id, String Name, String Birthday, String weight, String height, String gender, String Protein, String carbs, String fat, String Weightloss)
    {
        this.id = Id;
        this.Name = Name;
        this.Birthday = Birthday;
        this.weight = weight;
        this.height = height;
        this.gender = gender;
        this.Protein = Protein;
        this.carbs = carbs;
        this.fat = fat;
        this.weightloss = Weightloss;
    }

and after getting the text of the different text fields in the activity the data is saved like this:

  PersonalInfo info = new PersonalInfo(Id, Name, Birthday, Weight, Height, Gender, Protein, Carbs, Fat, Weightloss);

        databaseinfo.child(Id).setValue(info);
        Toast.makeText(this, "Data added", Toast.LENGTH_SHORT).show();


If anyone could help or give me a link to a tutorial that explains my problem, it would be much appriciated.

Rishabh Saxena :

Hi just add this all into a method and call it & replace 'server/saving-data/fireblog/posts' with your server node link and you will get the reponse from that node.

// Get a reference to our posts
final FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference("server/saving-data/fireblog/posts");

// Attach a listener to read the data at our posts reference
ref.addValueEventListener(new ValueEventListener() {
  @Override
  public void onDataChange(DataSnapshot dataSnapshot) {
    Post post = dataSnapshot.getValue(PersonalInfo.class);
    System.out.println(post);
  }

  @Override
  public void onCancelled(DatabaseError databaseError) {
    System.out.println("The read failed: " + databaseError.getCode());
  }
});

There are several types of event listeners are present & you can read all about retrieval of data from here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to retrieve child data from firebase realtime database on Swift 5

Retrieve child data from firebase realtime database

Retrieve a single data from Firebase Realtime Database

Retrieve history data from firebase realtime database

Couldnot retrieve data from firebase realtime database

Firebase: retrieve data from realtime database as an Int

How to retrieve data in Firebase realtime database?

How to retrieve a username from firebase realtime database

How to retrieve array data from children node in Firebase Realtime Database Java? (Firebase Recycler Adapter)

How to retrieve specific data from firebase realtime database when data changed

Unable to retrieve data from firebase realtime database on to recyclerview

Retrieve data from firebase realtime database and auto fill into textbox

Quickest way to retrieve specific data from Firebase realtime database?

Unable to retrieve data from firebase realtime database into web app

Retrieve mcq data from firebase realtime database with options

Retrieve data from Firebase Realtime Database to display I UIImage

How to read data from the Firebase realtime database

How to select data from firebase realtime database

How to retrieve a specific data from a node in Firebase Realtime Database using Android Studio?

how do i retrieve data from firebase realtime database using kotlin

How do I retrieve the child of the child of the child's data from my firebase Realtime database?

How can I retrieve only the latest data entry from firebase realtime database that frequently updates entries

How to retrieve latest entry from the firebase realtime database?

How to retrieve unique key from firebase realtime database

How to retrieve user email from Firebase Authentication to Realtime Database

How to properly retrieve value from Firebase Realtime Database?

How to retrieve values from my Firebase Realtime Database?

Firebase Realtime Database - retrieve data Android Studio

Firebase : Retrieve childByAutoID from Realtime Database