当现有用户使用相同的电子邮件地址和密码登录时,响应始终为“无法登录,请检查您的电子邮件和密码,然后重试”
private void loginUser(String email, String password) {
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()){
mLoginProgress.dismiss();
Intent mainIntent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(mainIntent);
finish();
}
else {
mLoginProgress.hide();
Toast.makeText(LoginActivity.this,
"Cannot sign in. Please check your email and password and try again.", Toast.LENGTH_SHORT).show();
}
}
});
}
答案 0 :(得分:2)
当响应成功时,您通过使用!
表示
(!task.isSuccessful()) => (!true)
=> (false)
所以删除否定运算符(!
)
if (task.isSuccessful())
代码
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()){ // success
//..code
}
else { // failure
//..code
}
}
});
}
答案 1 :(得分:2)
这是因为你使用'!' NOT opertor成功,即如果登录不成功则输入if子句,删除!它会正常工作。