Android Firebase.child()和.hasChild()会给出不规则的结果
我试图使用密钥检查firebase节点是否存在。例如,我正在查看节点“child\u value”是否作为“parent\u value”的子节点存在 例如。 我的数据库引用指向“父值”。Android Firebase.child()和.hasChild()会给出不规则的结果,android,firebase,firebase-realtime-database,Android,Firebase,Firebase Realtime Database,我试图使用密钥检查firebase节点是否存在。例如,我正在查看节点“child\u value”是否作为“parent\u value”的子节点存在 例如。 我的数据库引用指向“父值”。 语句.child(“child_值”)返回子值的节点 语句.hasChild(“child\u值”)返回False 当子节点确实存在时,checking.haschild()返回False时,是什么导致这种奇怪的行为 编辑:代码段 //Entire code block below is inside of
语句
.child(“child_值”)
返回子值的节点
语句.hasChild(“child\u值”)
返回False
当子节点确实存在时,checking.haschild()返回False时,是什么导致这种奇怪的行为
编辑:代码段
//Entire code block below is inside of another singlevaluevent listener, don't know if that would cause any problems
DatabaseReference ref = FirebaseDatabase.getInstance().getReference()
.child("Values");
ref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull Datasnapshot dataSnapshot){
if(dataSnapshot.hasChild(key) {
//Would expect the flow to end up here since the child exists
}
else {
//Flow ends up here
}
}
突然想到的第一个问题是,是否启用了磁盘缓存(使用启用持久性(true)
)。如果是这样,使用addListenerForSingleValueEvent
可能会导致使用过时快照调用onDataChange
。@FrankvanPuffelen我确实启用了磁盘缓存。对于db引用,执行此操作的方法是.keepSynced(False)。或者不建议这样做。使用磁盘持久性和单值事件侦听器不能混合使用。看见