I'm not sure it's disconect or DatabaseErrors event. First I have a dialog show when start loading data on Firebase, and then I want to dismiss that dialog in two case :
have internet: load data success, and I dissmiss dialog in onDataChange.
no internet connection or turn off wifi quickly when app start.
In second case, I think It's will call onCancelled, and in that method, I will dismiss dialog. But in real, it's not call onCancelled.
So, how I can dissmiss dialog on second case. Here's my code
private void getCategory() {
mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.child(ReferenceToFirebase.CHILD_CATEGORIES)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//do something
//then dismiss dialog
mDialog.dismiss();
}
@Override
public void onCancelled(DatabaseError databaseError) {
mDialog.dismiss();
}
});
}