【发布时间】:2022-01-19 18:18:56
【问题描述】:
我是 android studio 的新手,真的可以使用您的帮助。 我在使用firebase auth登录后遇到登录页面代码问题。我会从登录页面的firestore中检索一个int值,然后决定下一步去哪里(布局)。它总是转到主要活动而不是个人详细信息2(即,即使 fristtimekey = 1 中的值,if 条件也始终为假)。
请检查问题出在 if(fristtimekey ==1),除此之外一切都正确(logcat 也正确,其中值为 1)。
这是我的代码:
fAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(Login.this, "LogedIn succesfully", Toast.LENGTH_SHORT).show();
userid = fAuth.getCurrentUser().getUid();
DocumentReference docRef = foster.collection("users").document(userid);
DocumentReference document = foster.document("users/email");
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
fristtimekey = document.getLong("Frist time");
Log.d("TAG", String.valueOf(fristtimekey));
Log.d("TAG", "DocumentSnapshot data: " + document.getLong("Frist time") + " int: " + fristtimekey);
} else {
Log.d("TAG", "No such document");
}
} else {
Log.d("TAG", "get failed with ", task.getException());
}
}
});
progressBar.setVisibility(View.GONE);
if (fristtimekey == 1) {
startActivity(new Intent(getApplicationContext(), MainActivity.class));
} else {
startActivity(new Intent(getApplicationContext(), PersonalDetails2.class));
}
} else {
Toast.makeText(Login.this, "LogedIn unsuccesfully", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
}
}
});
【问题讨论】:
标签: java android firebase if-statement google-cloud-firestore