从一个新手,我找不到明确的答案。
已更新
我尝试了一个布尔值(nameExists)来查看FirebaseDb中是否存在userName,所以我确实...
public void addNameToFirebase() {
... gets name from editText
Firebase mCheckForNameRef = new Firebase(Config.FIREBASE_URL_BMN);
mCheckForNameRef.child(grabbedname).child(grabbedname).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
boolean nameExists = (Boolean) snapshot.getValue();
if (!nameExists) { // Does not exist yet - So create
System.out.println(snapshot.child("name").getValue());
// Want too see whats going on in system.out printLn - how?
UserName msg = new UserName();
msg.setDate(new Date());
msg.setText(grabbedname);
msg.setmPoints(505);
msg.setmCounter(1);
Utils.saveUserName(msg, mConvoId, listId);
} else { // Already exists - So Update
System.out.println(snapshot.child("name").getValue());
// Want too see whats going on in system.out printLn- how?
Counter nameCount = new Counter();
nameCount.setDate(new Date());
nameCount.setText(grabbedname);
msg.setmPoints(0);
nameCount.setmCounter(3);
nameCount.setmGender(Integer.valueOf(currentGender));
Utils.updateUserName(nameCount, mConvoId, listId);
}
}
@Override
...
});
}
可能导致此行为的原因是什么?它创建newUser然后当选择相同的名称时,它应该执行第二个块。
我还应该补充说,如果有任何线索,我已经启用了磁盘持久性。