有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使用带多FirestoreRecyclerAdapter的房间?

我在MainActivity中使用4RecycleView,它使用FirestoreRecyclerAdapter从Cloud Firestor加载数据。现在我想使用RoomReceiptActivity中的用户创建收据

我做了所有的工作人员,但当我试图删除和更新Room中的项目时,出现了一些错误。我的应用程序正在崩溃,所以我想问一下,我所做的与我所做的是否存在冲突?如果没有,请用最佳实践来指导我。提前谢谢

Error message


共 (1) 个答案

  1. # 1 楼答案

    使用Cloud Firestore时,offline persistence

    For Android and iOS, offline persistence is enabled by default. To disable persistence, set the PersistenceEnabled option to false.

    这意味着Firestore将在用户设备上创建整个数据库的本地(内部)副本。因此,不需要添加额外的本地数据库,也可以实现您想要的相同功能,因为默认情况下,本地数据库已经存在

    此外,如果只需要从缓存中获取数据,可以通过DocumentReference.get(Source source)Query.get(Source source)方法实现

    By default, get() attempts to provide up-to-date data when possible by waiting for data from the server, but it may return cached data or fail if you are offline and the server cannot be reached. This behavior can be altered via the Source parameter.

    因此,我们现在可以将参数传递给源DocumentReferenceQuery,这样我们就可以强制从server onlychache only或尝试服务器检索数据,并返回到缓存