无法使用Cloud Firestore离线调用addOnCompleteListener [英] addOnCompleteListener not called offline with cloud firestore
问题描述
我一直在使用新的Cloud Firestore数据库编写应用程序.尽管启用了脱机持久性,但许多事情在脱机时无法顺利进行的事实非常有效. 例如,我执行以下操作:
I have been writing an app using the new cloud firestore database. It works great except the fact that many things are not working smoothly when offline although the offline persistence is enabled. For instance I do the following:
ref.delete().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
//Do something
} else {
//Do another thing
}
}
});
但是,离线时永远不会调用onComplete
方法.我想关闭活动并在发生这种情况时显示一些Snachbar.但是,由于从来没有这样做,所以活动仍然是开放的.我正在使用android studio模拟器.
However the onComplete
method is never called when offline. I want to close the activity and show some Snachbar once this happens. But as it never does, the activity remains open. I am using android studio emulator.
谢谢
推荐答案
写入数据库的操作定义为一旦实际提交到后端即发出信号通知完成.结果,它可以按预期工作:离线时,它们不会表示已完成.
Operations that write to the database are defined to signal completion once they've actually committed to the backend. As a result this is working as intended: while offline they won't signal completion.
请注意,即使您不等待删除操作完成,Firestore客户端也会在内部保证您可以读取自己的写入内容.
Note that the Firestore clients internally guarantee that you can read your own writes even if you don't wait for completion of the task from delete.
在大多数情况下,这意味着您无需等待该任务完成.您对此有兴趣吗?
For the most part this means that you shouldn't need to wait for this task to complete. Is there any particular reason you're interested in doing so?
这篇关于无法使用Cloud Firestore离线调用addOnCompleteListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!