Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
In last blog , we discussed how to write data to your firebase realtime database from your android app.
Firebase database provides you three listeners, through which you can retrieve the data.
These are :
A brief insight to these methods,
addValueEventListener : This listener helps you to detect the change in the data at a particular path (including the children at that particular path). This listener keeps listening till your app is connected to the firebase.
addListenerForSingleValueEvent :This listener helps you to detect the change in the data at a particular path (including the children at that particular path). This listener listens exactly once and provides you the data as per the change until this event was triggered.
addChildEventListener : When working with the lists of data, we should use this listener rather than the above mentioned two. This listener helps you listen to the events related to the particulars of a child node of the root. The methods in this listener are triggered in response to specific operations that happen to the children of a node from an operation.
For more details on these , please refer to the Firebase documents or click here .
To read data, i have used the addChildEventListener, so will discuss that in more detail and along with the code snippet.
All you need to do is to get to the exact node on your realtime database and attach a listener to it. You will recieve the data as an object of DataSnapshot, and you need to extract the data from this as per your need and add to your list.
Code :
Similary you can change any of the methods in this listener as per your need.
The names of the methods itself makes pretty clear on what exactly would be the scope of the method.
You can also use “addValueEventListener” or “addListenerForSingleValueEvent” , in these you will have to override two methods, namely :
“onDataChange” will return the data as an object of DataSnapshot and you can use it in a similar manner as depicted in the code.
That’s all !
You really need to structure your database well so that you can read the data with ease.
For seeing last blog , please click here
Thanks !
Keep coding and keep sharing : )
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Name
Email
Subject
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.