【发布时间】:2016-11-16 11:39:53
【问题描述】:
如果我以下列方式在活动中使用监听器:
// Read from the database
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
String value = dataSnapshot.getValue(String.class);
Log.d(TAG, "Value is: " + value);
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w(TAG, "Failed to read value.", error.toException());
}
});
附加一个匿名侦听器(未附加到变量的事件), 我还需要删除它吗?
*我在onStart() 上设置了它,并需要它运行到onStop() / onDestroy()
什么时候需要移除监听器?
【问题讨论】:
-
如果您只有一个 EventListener 而不是您不必删除,它会在侦听器下载列表中的数据时自动删除。
标签: android firebase firebase-realtime-database