特定のフィールドの値が true の場合に、firebase ref から addValueEventListener リスナーを削除したいと考えています。
ValueEventListener valueListener=null;
private void removeListener(Firebase fb){
if(valueListener!=null){
**fb.removeEventListener(valueListener);**
}
}
String key="https://boiling-heat-3083.firebaseio.com/baseNodeAttempt/" + userId+"/"+nodeType+"/"+nodeId+"/data";
final Firebase fb = new Firebase(key);
valueListener=fb.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snap) {
final HashMap<String, Object> data=(HashMap<String, Object>) snap.getValue();
if( data.get("attemptFinish_"+nodeId)!=null){
boolean title = (boolean) snap.child("attemptFinish_"+nodeId).getValue();
if(title){
removeListener(fb);
}
}
}
@Override
public void onCancelled() {
// TODO Auto-generated method stub
}
});
しかし、 addValueEventListener は削除されておらず、その firebase ref に対して呼び出されています。必要に応じて、firebase refからリスナーを削除する方法を教えてください。