首页 > 解决方案 > 应用重启后 Firebase 磁盘持久性不起作用

问题描述

我对 firebase 和磁盘持久性有疑问。当我离线并使用时setValue

 mDatabase.child(spamuId).setValue(contactSpam);

当我在没有重新启动应用程序的情况下上线时,我的数据库会更新,但是当我关闭应用程序并激活互联网并打开应用程序时,数据库不会更新。通常keepSync()不需要,如果我理解得很好,它会将所有 databaseReference 复制到本地存储。我不知道我做错了什么我把它放在我的应用程序类中:

 public class MyApplication extends Application {
    @Override
    public void onCreate() {
        FirebaseDatabase.getInstance().setPersistenceEnabled(true);

因此,如果有人能给我解释,我将不胜感激。

编辑:logcat

当我不重新启动应用程序并且没关系时:

0-556/practical_solutions.fr.numfilterpro D/Persistence:在/ContactReportNoSpamFr/-LDGJofYHq5hTpwD8LqV/date 1ms 内共保留 1 行并删除 1 行

当我重新启动时:我没有看到任何持久性消息。

编辑:在我的应用程序中使用简单的计数测试按钮记录:

D/持久性:交易完成。已用时间:20 毫秒

D/RepoOperation:中止路径的事务:/test。受影响:/测试

D/PersistentConnection: pc_0 - 试图获取授权令牌

W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() 返回 Gms: com.google.android.gms.internal.zzdze@d0effca

D/PersistentConnection: pc_0 - 获取令牌时出错:发生网络错误(例如超时、连接中断或无法访问主机)。pc_0 - 计划连接尝试

D/ConnectionRetryHelper:在 480 毫秒内安排重试

D/PersistentConnection: pc_0 - 试图获取授权令牌 W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() 返回 Gms: com.google.android.gms.internal.zzdze@d0effca

D/PersistentConnection: pc_0 - 获取令牌时出错:发生网络错误(例如超时、连接中断或无法访问主机)。pc_0 - 计划连接尝试

D/ConnectionRetryHelper:在 1138 毫秒内安排重试

D/PersistentConnection: pc_0 - 试图获取授权令牌

W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() 返回 Gms: com.google.android.gms.internal.zzdze@d0effca

D/PersistentConnection: pc_0 - 获取令牌时出错:发生网络错误(例如超时、连接中断或无法访问主机)。pc_0 - 计划连接尝试

D/ConnectionRetryHelper:在 1404 毫秒内安排重试

标签: javaandroidfirebasefirebase-realtime-database

解决方案


您是否在清单中添加此行

android:name=".MyApplication"

如果不添加并卸载应用程序并重新安装

<application
    android:name=".MyApplication"
    android:allowBackup="true"
    android:hardwareAccelerated="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"

推荐阅读