问题
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
OnSuccessListenerorOnFailureListeneris 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