Firebase OnSuccessListener is being called when it should fail

大兔子大兔子 提交于 2020-01-14 14:24:30

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/38836277/firebase-onsuccesslistener-is-being-called-when-it-should-fail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!