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 savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_meal_details); if (mDatabase == null) { mDatabase = FirebaseDatabase.getInstance().getReference(); FirebaseDatabase.getInstance().setPersistenceEnabled(true); // ... } // FirebaseDatabase.getInstance().setPersistenceEnabled(true); mDatabase = FirebaseDatabase.getInstance().getReference();
According to Firebase Documentations setPersistenceEnabled is to be called only once (before any other instances of FirebaseDatabase are made)
So the solution to this issue for me was the following
For Example
class MyFirebaseApp extends android.app.Application @Override public void onCreate() { super.onCreate(); /* Enable disk persistence */ FirebaseDatabase.getInstance().setPersistenceEnabled(true); }
For Example
in your application tag add the following
android:name="com.example.MyFirebaseApp"
this should work fine.
Also don't use setPersistenceEnabled in any other Activity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With