I want to remove addValueEventListener listener from a firebase ref when value of particular field is true.
ValueEventListener valueListener=null;
private void
private DatabaseReference dbRef;
ValueEventListener mSendEventListner;
dbRef = FirebaseDatabase.getInstance().getReference().child("users").child(phone);
ValueEventListener valueEventListener = new ValueEventListener()
{
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists())
{
//
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
//
}
};
dbRef.addValueEventListener(valueEventListener);
mSendEventListner = valueEventListener;
//REMOVE VALUE EVENTLISTNER...
@Override
protected void onDestroy()
{
super.onDestroy();
if (mSendEventListner != null) {
dbRef.removeEventListener(mSendEventListner);
}
}