I am having a problem when I try to setPersistence in fIREBASE,can someone please explain on how to go about it,
protected void onCreate(Bundle savedInstance
If you extend a ContentProvider
in your app you can call FirebaseDatabase.getInstance().setPersistenceEnabled(true);
in your ContentProvider
's onCreate()
method because this method is called even before the onCreate()
method of your launcher activity. This will also be useful when you use TaskStackBuilder
in your app to create a synthetic stack of activities to skip some activities and move forward like when you use in app notifications. So when you come back to the launcher activity moving backwards you might have already used FirebaseDatabase
instance somewhere in your application and the error you are getting might pop up in this case as well.
This solution works for me without extends android.app.Application
private static FirebaseDatabase firebaseDatabase;
if (firebaseDatabase == null) {
firebaseDatabase=FirebaseDatabase.getInstance();
firebaseDatabase.setPersistenceEnabled(true);
}
/* Do your other stuff */
OR
if (savedInstanceState == null) {
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
}