姬長信(Redy)

android – Firebase:setPersistenceEnabled和keepSy…


我以为我使用以下所有聊天对话数据的时间都可以随时离线使用.以某种方式不是,所有节点都从服务器加载.
FirebaseDatabase.getInstance().setPersistenceEnabled(true);

然后,根据DOCS:

Persistence Behavior : By enabling persistence, any data that we sync while online will be persisted to disk and available offline, even when we restart the app. This means our app will work as it would online using the local data stored in the cache.

如果setPersistenceEnabled(true)时数据已经脱机可用; ,为什么我需要keepSynced(true)?

DatabaseReference r = FirebaseDatabase.getInstance().getReference("chat/roomid");
r.keepSynced(true);