Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Firebase Offline Best Practices

Tags:

I am stuck at understanding the concept of making Firebase App Offline. As per the documentation, we need to call:

FirebaseDatabase.getInstance().setPersistenceEnabled(true); 

But where should we call this? Is it should be used in every Activity of the Application? Because, when I am using this inside my Application class onCreate() method, my app crashes continuously.

So what is the best practice we should follow to make our app offline.

One more doubt is the difference between the above one and DatabaseReference.keppSynced(true);

like image 316
Chandra Sekhar Avatar asked May 29 '16 07:05

Chandra Sekhar


1 Answers

Create an Application Class

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

And Change your manifest as

<application     android:name=".MyApp"     android:allowBackup="true"     android:icon="@mipmap/ic_launcher" 
like image 169
Jinson Paul Avatar answered Sep 24 '22 11:09

Jinson Paul