【发布时间】:2021-05-04 01:27:00
【问题描述】:
我想检查是否存在带有特定电子邮件的密钥。如果存在,我需要获取键的值(我的应用程序中用户的唯一 id)并检查在应用程序中输入的 id 是否与从数据库中获取的 id 匹配。但问题是我的 onDataChange() 在我执行相等性检查后响应。可以做什么?
rootRef.child("shortlisted").child(email1).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NotNull DataSnapshot snapshot) {
try {
if (snapshot.getValue() != null) {
try {
aac = snapshot.getValue().toString();
System.out.println("STRINGAAC"+aac);
} catch (Exception e) {
e.printStackTrace();
}
} else {
//user doesnt exist
Log.e("TAG", " it's null.");
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
System.out.println("STRINGAAC"+aac);
if(aac.equals("not found"))
{
Toast.makeText(globalContext,"not found", Toast.LENGTH_SHORT).show();
}
if(aac.equals(aacid_s))
{
Toast.makeText(globalContext,"Key Matched value", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(globalContext,"Key un-Matched value", Toast.LENGTH_SHORT).show();
}
【问题讨论】:
标签: android firebase firebase-realtime-database