Android Firebase - Setpersistenceenabled(true) Crashing The App
Solution 1:
This part mFirebaseInstance.setPersistenceEnabled(true);
should be just in first Activity. It's shouldn't be called more than once.
Better solution would be to put that line in onCreate method of your Application class. You can read more about it here.
Solution 2:
Remove the line mFirebaseInstance.setPersistenceEnabled(true);
from your RegisterActivity
class.
Make a custom class which should extend Application and write it there.
Example :
publicclassJustExampleextendsApplication {
@OverridepublicvoidonCreate() {
super.onCreate();
if (!FirebaseApp.getApps(this).isEmpty())
{
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
}
}
}
Solution 3:
booleanflag=true; //before onCreate() method//inside onStart() Methodif(flag)
{
firebaseDatabase.setPersistenceEnabled(true);
flag = false;
}
Solution 4:
You can use a Model class and use Method inside it such as the one mentioned below.
publicclassDatabaseUtility {
privatestatic FirebaseDatabase database;
publicstatic FirebaseDatabase getDatabase(){
if(database==null){
database=FirebaseDatabase.getInstance();
database.setPersistenceEnabled(true);
}
return database;
}
}
This will return database instance and you can use database.getReference();
method to get Root reference. This will also save some time if the database object is already present.
Solution 5:
You just simply uninstall the previously installed app. And let it install the fresh app. It will resolve the problem.
Post a Comment for "Android Firebase - Setpersistenceenabled(true) Crashing The App"