So I disconnected my internet connection and tested my app. When I add something to the database, I check if it was successfully added using the default OnSuccessListener. However, even when my application is in Airplane mode or there is no internet connection, OnSuccessListener is getting called, and OnFailureListener isn't.
This is weird, it shouldn't get called.
Code:
database.child("blah").child(key).setValue(objects).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(@NonNull Void T) {
//Do whatever
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
//display error message
}
});
But for some reason, OnSuccessListener is still being called. This is unbelievably irritating. Even when I add an OnCompleteListenerinstead with if(task.isSuccess()) it does the same.
ِAs The Doc Says:
Firebase apps remain responsive even when offline because the Firebase Realtime Database SDK persists your data to disk. Once connectivity is reestablished, the client device receives any changes it missed, synchronizing it with the current server state.
so your data has successfully added to the disk and once you go online it will be synchronized to the cloud.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With