Why is not the my listeners hit here in this Fires

2020-03-30 07:15发布

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条回答
别忘想泡老子
2楼-- · 2020-03-30 07:30

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.

查看更多
登录 后发表回答