Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access Firebase data without using addValueEventListener

Is there a way to access firebase data without having to use the addValueEventListener? This way, I can access the data whenever I need, as opposed to being restricted to access it only when there is a data change.

I am coding in Java. Thanks :)

like image 378
kmindspark Avatar asked Jun 10 '16 00:06

kmindspark


1 Answers

The only way to get the value of a location in your database is one of the getValue() methods of DataSnapshot. The only way to get a DataSnapshot is as a parameter of a callback method of one of the listeners: ValueEventListener or ChildEventListener.

You can get the current value of a location one time using Query.addListenerForSingleValueEvent(). The listener callback method, onDataChange(), will fire once with a DataSnapshot that provides the value of the data at the location. To get a callback for the current value and each subsequent change, use Query.addValueEventListener(). To get the current values and changes to the children of a location, use Query.addChildEventListener().

like image 97
Bob Snyder Avatar answered Oct 18 '22 08:10

Bob Snyder