I want to remove addValueEventListener listener from a firebase ref when value of particular field is true.
ValueEventListener valueListener=null;
private void
I hope this will help you... just yo can use this method, it's work for me...
private DatabaseReference dbRef;
Write from onCreate()
FirebaseDatabase database = FirebaseDatabase.getInstance();
dbRef= database.getReference("YOUR_PATH").child("KEY_NAME");
InitListener();
dbRef.addValueEventListener(valueEventListener); // ADDIND_LISTENER
Write from onDestroy()
if (dbRef!=null){
dbRef.removeEventListener(valueEventListener);
valueEventListener=null;
dbRef=null;
}
Listener
private void InitListener(String templeId) {
valueEventListener=new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
}