The guide for how to Retrieve Data explains that:通过将异步侦听器附加到FirebaseDatabase参考.会在一次触发监听器数据的初始状态,并在数据更改时再次显示. Firebase data is retrieved by attaching an asynchronous listener to a FirebaseDatabase reference. The listener is triggered once for the initial state of the data and again anytime the data changes.因此,当您将侦听器附加到某个位置时, onDataChanged()触发并为您提供当前值.So when you attach a listener to a location, onDataChanged() fires and gives you the current value.在标题为一次读取数据"的部分中,指南指出:In the section titled Read Data Once, the guide states:在某些情况下,您可能希望一次调用一次回调立即删除,例如初始化您的UI元素时不要指望改变.您可以使用 addListenerForSingleValueEvent()方法可简化此情况:触发一次,然后不再触发. In some cases you may want a callback to be called once and then immediately removed, such as when initializing a UI element that you don't expect to change. You can use the addListenerForSingleValueEvent() method to simplify this scenario: it triggers once and then does not trigger again. 这篇关于如何一次获取Firebase数据库的值(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-24 14:12