[英]Firebase.database().ref(“RefNode”).set(null) triggers OnDataChanged of that reference
I have nodejs server and an android client . 我有nodejs服务器和一个android客户端 。 Both are connected to my firebase database . 两者都连接到我的firebase数据库 。 When the server sets the "RefNode"
to null
, the onDataChanged
Callback, that is set on that "RefNode"
on the andriod side, gets called. 当服务器将"RefNode"
为null
,将onDataChanged
在"RefNode"
侧的"RefNode"
上设置的onDataChanged
回调。
Is there any way to avoid it being called in the special case when the "RefNode" was set to null while for all other cases it should get called. 有什么方法可以避免在特殊情况下将“ RefNode”设置为null时调用它,而在所有其他情况下都应调用它。
I have a listener on a node "RefNode"
in my android application as given below: The OnDataChanged() callback is getting called even when the "RefNode"
was set to null
by the nodejs server. 我在android应用程序中的节点"RefNode"
上有一个侦听器,如下所示:即使nodejs服务器将"RefNode"
设置为null
,也会调用OnDataChanged()回调。
FirbaseDatabase.getInstance().getReference().child("RefNode").addValueEventListener( new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
if(dataSnapshot.getValue()!=null) {
Log.v(TAG, "got here even when the Refnode was set to null");
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
// The listener got cancelled
}
});
I have found the problem I had attached the event listener twice. 我发现我已附加两次事件侦听器的问题。 I had made the ValueEventListener a field of the class the and attached it twice. 我已经将ValueEventListener设为类的字段,并将其附加了两次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.