Android - Firestore离线数据同步

Android - Firestore offline data synchronization

firestore documentation 说:

Cloud Firestore caches data that your app is actively using, so the app can write, read, listen to, and query data even if the device is offline. When the device comes back online, Cloud Firestore synchronizes any local changes back to Cloud Firestore.

现在,我已经对此进行了测试,显然,设备重新联机并不是同步发生所需要的全部。

我通过以下方式测试过:

* 我用了 FirebaseFirestore.getInstance().collection("foo").document().set(bar)


本次测试结束时,数据没有发送到firestore远程数据库。我需要再次打开我的应用程序才能发送数据。

但是,我仍然不确定究竟是什么触发了同步。是只有我的应用程序处于打开状态还是需要打开套接字才能进行 firestore?


我测试了最后一件事,即:

本次测试结束时,数据未发送到 firestore 远程数据库。

但是,我还是不确定究竟是什么触发了同步。它可能是打开的套接字,但如果是这样,是否需要在与我的 collection 相关的查询中打开它?


我的最后一个问题是:

究竟是什么触发了同步?

Is it only my app being open or does it needs to have an open socket to firestore?

这取决于"my app being open"是什么意思。如果它意味着在前台,那可能没有太大意义,因为你可以在后台有作业 运行,并打开 Firestore 套接字。


It's probably the open socket, but if so, does it need to be open on a query related to my collection?

不,不是。 数据库任何部分的任何 CRUD 操作 都会启动同步,无论是通过查询集合还是获取、保存、更新或删除文档。