将新值设置为firebase数据库(在firebase控制台上检查),但在查询数据快照上会重新获取旧值。
final Query query = FirebaseDatabase.getInstance().getReference(DEVICES_TABLE).orderByChild("deviceUniqueId").equalTo(deviceUniqueId);
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Device device;
if (dataSnapshot.getChildren().iterator().hasNext()) {
device = dataSnapshot.getChildren().iterator().next().getValue(Device.class);
if (device.getIsEnable() == 1) {
loginView.onError(loginView.getContext().getString(R.string.error_device_disable));
doCyberoamLogout(mUserName, location);
} else {
switch (mMessage) {
case CYBEROAM_LOGIN_SUCCESS_MESSAGE:
//login successful
Toast.makeText(activity, "Cyberoam login success.", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
getEmailUsingCyberoamId(mUserName, mPasswod);
}
}, 5000);
break;
case CYBEROAM_WRONG_PASSWORD:
signOutFromFirebase();
loginView.onError(CYBEROAM_WRONG_PASSWORD);
break;
case CYBEROAM_MAX_LOGIN_LIMIT:
signOutFromFirebase();
loginView.onError(loginView.getContext().getResources().getString(R.string.prompt_max_login_limit));
break;
default:
signOutFromFirebase();
loginView.onError(loginView.getContext().getResources().getString(R.string.action_cyberoam_login_failed));
break;
}
}
query.removeEventListener(this);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
答案 0 :(得分:0)
您需要删除此行:
query.removeEventListener(this);
启用持久性 addValueEventListener 首先返回缓存数据,下次返回新数据。