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 :)
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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With