Why is not the my listeners hit here in this Firestore set

强颜欢笑 提交于 2020-01-11 07:28:06

问题


I have this strange thing where OnSuccessListener or OnFailureListener stopped being called. Everything works ok but when I turn of mobile data and Wifi non of the OnSuccessListener or OnFailureListener is being called.

If I put a breakpoints on the below code ref.set(update)..... the breakpoints are indeed hit but non of the OnSuccessListener or OnFailureListener fires

 Map<String, String> update = new HashMap<>();
    update.put(ByteData.DATA, data);
    DocumentReference ref = firestore
            .collection(DEVICE_DATA)
            .document(FirestoreManager.getInstance().getUserId())
            .collection(DEVICE_DATA_STREAM)
            .document(batteryEntity.getEntityId());
    ref.set(update).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
             // do some stuff
        }
    }).addOnSuccessListener(new OnSuccessListener<Void>() {
        @Override
        public void onSuccess(Void aVoid) {
             // do some stuff
        }
    });

回答1:


when I turn of mobile data and Wifi [neither] the OnSuccessListener or OnFailureListener is being called

That is the expected behavior. The completion listeners are only called once the data has been written on (or rejected by) the server.

The listener doesn't fire for local write operation. If the local write operation were to fail, the client will raise a regular exception.



来源:https://stackoverflow.com/questions/57444042/why-is-not-the-my-listeners-hit-here-in-this-firestore-set

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