我有一个 Firebase 数据库,我用它来用 FirebaseUI 填充 ListView。一切正常(离线和在线),直到应用程序被杀死并在没有互联网的情况下重新启动。发生这种情况时,数据库是空的,一旦互联网恢复,它会完美同步所有内容。
我用:
Firebase.getDefaultConfig().setPersistenceEnabled(true);
但它不会改变任何东西。即使在杀死应用程序后,我应该怎么做才能让 Db 离线?
database = FirebaseDatabase.getInstance(FirebaseApp.getInstance());
ref = database.getReference(FirebaseAuth.getInstance(FirebaseApp.getInstance()).getCurrentUser().getUid())
.child("Tasks");
Log.d(TAG,"User ID: " +FirebaseAuth.getInstance(FirebaseApp.getInstance()).getCurrentUser().getUid());
Log.d(TAG,"DB: " +database);
Log.d(TAG,"Ref: " +ref);
mAdapter = new FirebaseListAdapter<Task>(getActivity(), Task.class, R.layout.task_view,ref) {
@Override
protected void populateView(View v, Task model, int position) {
TextView task = (TextView) v.findViewById(R.id.task_text);
CheckBox checkBox = (CheckBox) v.findViewById(R.id.checkbox);
task.setText(model.getText());
checkBox.setChecked(model.getDone()==1);
}
};
listView.setAdapter(mAdapter);