java - 应用重启后 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 毫秒内安排重试
解决方案
您是否在清单中添加此行
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"
推荐阅读
- git - 关于使用 Github 组织 Repos 的最佳方式的问题
- javascript - 防止格式化的电话号码有 10 个重复的数字 RegEx
- c# - 我们如何将字符串从一个方法返回到主方法?
- android - Android:UI 未通过 MutableSet MutableLiveData 上的数据绑定刷新
- pandas - 对熊猫数据框的列应用差异
- python - 不断从python中的csv阅读器获取文件未找到错误
- python-3.x - 条件后返回 None 而不是 print 语句
- python - 如何为变量定义布尔值?
- python - 使用 OpenCV 在 MacOS 上将 jpg 转换为 bmp 很容易。可以用枕头做这项工作吗?
- c# - 我想在一个事件上创建一个计时器/秒表