是否可以读取Firebase数据而不附加任何侦听器? [英] Is it possible to read Firebase data without attaching any listeners?
问题描述
DataSnapshot
,而无需将EventListener附加到Firebase引用?或者还有其他一些方法可以直接从Firebase引用中读取某些类型的 ref.getValue()
等价的内容吗? Java SDK 提供了一个 addListenerForSingleValueEvent
方法,它相当于你的ref.getValue 。它的使用方式与 addValueEventListener
类似,但是只检索一个值。 新增了ValueEventListener(){
@Override $ b $ public void onDataChange(DataSnapshot snap){
System.out.println(snap.getName()+ - >+ snap.getValue());
}
@Override public void onCancelled(){}
});
像Frank提到的那样,REST API也是一个不错的选择。 b
I'm working on a Firebase Android app and need a way to read data from Firebase without actually attaching any listeners. I don't care in this particular instance if the data changes after the initial read. Is there a way I can directly access a DataSnapshot
without attaching an EventListener to a Firebase reference? Or is there some other way I can directly read from a Firebase reference with some sort of ref.getValue()
equivalent?
Thank you.
The the Java SDK provides a addListenerForSingleValueEvent
method, which is equivalent to your ref.getValue(). It is utilized just like addValueEventListener
, but only retrieves a single value.
fb.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snap) {
System.out.println(snap.getName() + " -> " + snap.getValue());
}
@Override public void onCancelled() { }
});
The REST API, as Frank mentioned, is also a great choice.
这篇关于是否可以读取Firebase数据而不附加任何侦听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!