如果我以以下方式在活动中使用侦听器:
// 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()
何时需要删除侦听器?