FirebaseFirestore different between OnCompleteListener, OnSuccessListener, OnCanceledListener and OnFailureListener

和自甴很熟 提交于 2020-01-11 14:03:12

问题


Can someone explain me how these Listener are different from each other?

AFAIK, If I use OnCompleteListener() I can check if task complete or not and if it complete I can still check that it success or not.

I confuse that when task failed. it happens because task not complete or task not success or it can occurs in both case. And how OnCanceledListener work? When it will be called? and what is the meaning of "Called when the Task is canceled successfully."?

Please explain me, I confuse of these Listener behavior?


回答1:


A Task is considered complete when the work represented by the Task is finished, regardless of its success or failure. So there may be or may be not an error, but you have to check for that. On the other side, a Task is successful when the work represented by the task is finished, as expected, with no errors.

OnFailureListener is called when a Task fails with an exception. So you can get the message from the Exception to see the reason why your Task failed.

OnCanceledListener is called when the Task is canceled successfully, which means that every Task has a cancel() method and once this method completes successfully, this listener is invoked.

Please also note, if there is a loss of network connectivity (there is no network connection on user device), neither onSuccess() nor onFailure() are triggered. This behavior makes sense, since the Task is only considered completed when the data has been committed (or rejected) on the Firebase servers.



来源:https://stackoverflow.com/questions/53665793/firebasefirestore-different-between-oncompletelistener-onsuccesslistener-oncan

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