FirebaseFirestore在OnCompleteListener,OnSuccessListener,OnCanceledListener和OnFailureListener之间有所不同 [英] FirebaseFirestore different between OnCompleteListener, OnSuccessListener, OnCanceledListener and OnFailureListener

查看:70
本文介绍了FirebaseFirestore在OnCompleteListener,OnSuccessListener,OnCanceledListener和OnFailureListener之间有所不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释一下这些监听器之间的区别吗?

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

AFAIK,如果我使用OnCompleteListener(),我可以检查任务是否完成,如果任务完成,我仍然可以检查任务是否成功.

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.

当任务失败时,我对此感到困惑.发生这种情况的原因是任务未完成或任务未成功,或者两种情况都可能发生.以及OnCanceledListener如何工作?什么时候会被调用?以及成功取消任务时调用"是什么意思?

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?

推荐答案

当Task所代表的工作完成时,无论其成功与否,都认为Task已完成.因此可能有错误也可能没有错误,但是您必须检查该错误.另一方面,按预期完成任务所代表的工作,且没有没有错误.

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.因此,您可以从异常"中获取消息,以查看任务失败的原因.

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,这意味着每个Task都有一个cancel()方法,并且该方法成功完成后,将调用此侦听器.

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.

还请注意,如果网络连接丢失(用户设备上没有网络连接),则不会触发onSuccess()onFailure().这种行为是有道理的,因为只有在Firebase服务器上已提交(或拒绝)数据后,才认为任务已完成.

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.

这篇关于FirebaseFirestore在OnCompleteListener,OnSuccessListener,OnCanceledListener和OnFailureListener之间有所不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆