如何在不使用addValueEventListener的情况下访问Firebase数据 [英] How to access Firebase data without using addValueEventListener

查看:118
本文介绍了如何在不使用addValueEventListener的情况下访问Firebase数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法访问firebase数据而无需使用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.

我用Java编码。谢谢:)

I am coding in Java. Thanks :)

推荐答案

获取数据库中某个位置值的唯一方法是 getValue() DataSnapshot <的方法/ A>。获取 DataSnapshot 的唯一方法是作为其中一个侦听器的回调方法的参数: ValueEventListener ChildEventListener

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.

您可以使用 Query.addListenerForSingleValueEvent()。侦听器回调方法 onDataChange()将使用 DataSnapshot 触发一次,该方法提供数据的值。地点。要获取当前值和每次后续更改的回调,请使用 Query.addValueEventListener()。要获取某个位置的子项的当前值和更改,请使用 Query.addChildEventListener()

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().

这篇关于如何在不使用addValueEventListener的情况下访问Firebase数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆