addOnCompleteListener 未通过云 Firestore 离线调用 [英] addOnCompleteListener not called offline with cloud firestore

查看:16
本文介绍了addOnCompleteListener 未通过云 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?

这篇关于addOnCompleteListener 未通过云 Firestore 离线调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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