private void loginUser(final String email, final String password) {
auth.signInWithEmailAndPassword(email,password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(!task.isSuccessful())
{
if(password.length() < 6)
{
Snackbar snackBar = Snackbar.make(activity_main,"Password length must be over 6",Snackbar.LENGTH_SHORT);
snackBar.show();
}
}
else{
startActivity(new Intent(MainActivity.this,DashBoard.class));
}
}
});
答案 0 :(得分:1)
if (!email.equals("") && !password.equals("")){
// this part will execute only when email and password are not null/empty.
// and the app can continue to make an attempt for login.
loginUser(email,password);
}else{
// if here... it means email or password field is empty or not being
// preserved correctly.
// so you can:
// 1. display msg here... for ex "pls fill all fields!"
// 2. or handle in any way you like
}
单击登录按钮时执行此操作。 希望这能解决问题。 :)