如何在不使用 addValueEventListener 的情况下访问 Firebase 数据
How to access Firebase data without using addValueEventListener
有没有一种无需使用 addValueEventListener 即可访问 firebase 数据的方法?这样,我可以在需要时随时访问数据,而不是仅在数据发生变化时才被限制访问。
我正在 Java 编码。谢谢:)
获取数据库中位置值的唯一方法是 DataSnapshot. The only way to get a DataSnapshot
is as a parameter of a callback method of one of the listeners: ValueEventListener or ChildEventListener 的 getValue()
方法之一。
您可以使用 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 数据的方法?这样,我可以在需要时随时访问数据,而不是仅在数据发生变化时才被限制访问。
我正在 Java 编码。谢谢:)
获取数据库中位置值的唯一方法是 DataSnapshot. The only way to get a DataSnapshot
is as a parameter of a callback method of one of the listeners: ValueEventListener or ChildEventListener 的 getValue()
方法之一。
您可以使用 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().