Native Shopify Mobile App with 20 new features
Kickstart your hyperlocal marketplace in Corona pandemic with a starter guide
Android App Development
iOS 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 184.108.40.206 release ready!
Owner and Founder. Opencart
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.
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
Keep coding and keep sharing : )
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.