So I was just trying out Firebase to update Toolbar label of activities from realtime database. I am getting the following error:
12-21 00:25:19.890 10295-10295/
Remove the line mFirebaseInstance.setPersistenceEnabled(true);
from your RegisterActivity
class.
Make a custom class which should extend Application and write it there.
Example :
public class JustExample extends Application {
@Override
public void onCreate() {
super.onCreate();
if (!FirebaseApp.getApps(this).isEmpty())
{
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
}
}
}
boolean flag = true; //before onCreate() method
//inside onStart() Method
if(flag)
{
firebaseDatabase.setPersistenceEnabled(true);
flag = false;
}
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.
You just simply uninstall the previously installed app. And let it install the fresh app. It will resolve the problem.
You can use a Model class and use Method inside it such as the one mentioned below.
public class DatabaseUtility {
private static FirebaseDatabase database;
public static 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.