如果不添加用户(添加包含用户详细信息的新文档),我正在检查用户是否已在数据库中进行预约。我的应用程序的问题是它同时运行 AddUser()
和 AlertUser()
函数:
DocumentReference docRef = firebaseFirestore.collection(group).document(userIdentity);
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()){
DocumentSnapshot documentSnapshot = task.getResult();
if (documentSnapshot != null) {
if (!documentSnapshot.exists()){
//User does not exist create the new user
addUser();
} else {
//User has already made an appointment show dialog
AlertUser();
}
}
}else {
Log.i("Key","Task not successfull");
}
}
});
最佳答案
此代码的作用是检查具有 userIdentity
id 的文档是否实际存在。如果不存在,则调用 addUser()
方法,否则调用 AlertUser()
。无法评估 if 语句的两个部分。所以这是一个或另一个。只有当您两次访问所有这些代码行时,您才能同时调用这两个方法。这意味着第一次创建用户并提醒第二次。要解决此问题,请从代码中删除两次调用上述代码的部分。
这是一个 Cloud Firestore 问题,而不是一个 Firebase 实时数据库问题,因此我相应地更改了标签。
关于java - 如何修复 Android Cloud Firestore 文档快照,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54764308/