问题描述
I am having a problem when I try to setPersistence in fIREBASE,can someone please explain on how to go about it,
我在尝试在fIREBASE中设置Persistence时遇到问题,请问有人可以解释一下如何去解决这个问题。 >保护无效的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();
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();
推荐答案
像这样(iirc):
if (mDatabase == null) {
FirebaseDatabase database = FirebaseDatabase.getInstance();
database.setPersistenceEnabled(true);
mDatabase = database.getReference();
// ...
}
这篇关于com.google.firebase.database.DatabaseException:必须在FirebaseDatabase实例的任何其他用法之前调用setPersistenceEnabled()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!