Android - Firebase Offline Best Practices

I am stuck in understanding the concept of creating a Firebase App Offline. In accordance with the documentation we need to call:

FirebaseDatabase.getInstance().setPersistenceEnabled(true);

But where should we call it? Should it be used in all application activities? Because when I use this inside my onCreate () class method, my application is interrupted continuously.

So what is the best practice that we must follow in order to disable our application.

Another doubt is the difference between the above and DatabaseReference.keppSynced(true);

+13
source share
5 answers

setPersistenceEnabled() , . , FIRApp.configure()

. , , . , .

, , , , , .

, , . , , , , , .

Firebase: https://firebase.google.com/docs/database/android/offline-capabilities

+9

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

    }
}

<application
    android:name=".MyApp"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
+14

, . , .

( ) , ( ) . , com.google.firebase: firebase-crash , your.app.packagename: background_crash. - . ,

FirebaseDatabase.getInstance().setPersistenceEnabled(true);

, Application, - Firebase . ,

if (!FirebaseApp.getApps(this).isEmpty())
        FirebaseDatabase.getInstance().setPersistenceEnabled(true);
+2

iOS , AppDelegate.swift "application: didFinishLaunchingWithOptions"

FirebaseDatabase.getInstance().setPersistenceEnabled(true); 

DatabaseReference.keppSynced(true);

viewController.

0

FirebaseDatabase.getInstance() setPersistenceEnabled ();.

onCreate . .

0

All Articles