gpt4 book ai didi

android - 如果应用被杀死,Firebase 不会同步离线缓存

转载 作者:IT老高 更新时间:2023-10-28 23:25:20 24 4
gpt4 key购买 nike

我正在设置离线持久化

FirebaseDatabase.getInstance().setPersistenceEnabled(true);

如所述in an earlier post ,但以下用例失败:

  1. 关闭手机上的互联网连接
  2. 尝试写入数据库
  3. 使用操作系统中用户的多任务菜单从内存中杀死应用
  4. 重新开启互联网连接
  5. 重新启动应用。 此时我希望通过恢复的网络连接将步骤 2 中的新记录发送到数据库,但这不会发生。(我的预期是否正确?)

示例代码:

static{
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
}

void updateValue(){
DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference("mydb");
dbRef.keepSynced(true);
dbRef.setValue("123");
}

请注意,如果我不从内存中终止应用程序,缓存将起作用:

  1. 关闭手机上的互联网连接
  2. 尝试写入数据库
  3. 重新开启互联网连接
  4. 一旦网络连接恢复,新记录就会发送到数据库。

最佳答案

根据火力基地 documentation

Transactions are not persisted across app restarts

Even with persistence enabled, transactions are not persisted across app restarts. So you cannot rely on transactions done offline being committed to your Firebase Realtime Database. To provide the best user experience, your app should show that a transaction has not been saved into your Firebase Realtime Database yet, or make sure your app remembers them manually and executes them again after an app restart.

关于android - 如果应用被杀死,Firebase 不会同步离线缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40880939/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com