Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase OnSuccessListener is being called when it should fail

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.

like image 661
Ali Bdeir Avatar asked Oct 22 '25 22:10

Ali Bdeir


1 Answers

ِ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.

like image 161
Moh'd Awad Avatar answered Oct 24 '25 14:10

Moh'd Awad