ibr*_*cic 5 android caching firebase firebase-realtime-database
我有一个从Firebase实时数据库中提取一些简单数据的应用程序,这里简单易用的就是我想拥有的流程.
如果手机连接到互联网:
如果手机处于离线状态
问题是我没有看到可能的方法来检测firebase缓存中是否有数据可用.因此,当手机处于脱机状态时,我无法看到我是否应该从firebase数据库显示本地存储的数据或缓存.
Firebase 会为您做到这一点。
即使您的应用暂时失去网络连接,Firebase 应用程序也能正常运行。
Also firebase apps automatically handle temporary network interruptions. Cached data is available while offline and Firebase resends any writes when network connectivity is restored.
If it is not enough and you need to work offline you can also enable the disk persistence just adding:
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
Run Code Online (Sandbox Code Playgroud)
More info here.
EDIT:
There is no way to know whether a value comes from the local cache or from the remote server.
只有一种方法可以了解您的应用当前是否连接到 Firebase 数据库服务器。
要实现这一点,您可以通过侦听该值来检测连接状态.info/connected。
| 归档时间: |
|
| 查看次数: |
1810 次 |
| 最近记录: |