Gür*_*sel 4 database android persistence local-storage firebase
我正在开发一个Android项目,我有一点问题.我正在使用firebase for database,我将数据离线保存到本地存储,但是当我database.setPersistenceEnabled(true);第二次设置时,我的应用程序崩溃了.我怎么能防止这种情况?我只在LoginActivity中设置了一次,我没有使用它,但我的应用程序在后台并重新打开应用程序我的应用程序因为持久性而崩溃.还有一个小问题,在将任何数据保存到firebase后,我的活动重新打开.我也不明白.谁能帮我?
你需要覆盖Application类,将它添加到清单然后database.setPersistenceEnabled(true);在那里调用
.例:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
}
}
Run Code Online (Sandbox Code Playgroud)
然后在你的AndroidManifest.xml:
<application
android:name=".MyApplication" <!--Relative path of MyApplication.java-->
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
tools:replace="android:supportsRtl"
android:supportsRtl="true"
android:theme="@style/AppTheme">
...
</application>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1778 次 |
| 最近记录: |