我有以下代码:
firebaseAuth.createUserWithEmailAndPassword(email, senha)
.addOnCompleteListener(CadastroActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()) {
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show();
Log.i("SuccessInCreateUser", task.getException().toString());
}
else{
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
Log.i("ErrorInCreateUser", task.getException().toString());
}
}
});
当我执行应用程序时,用户是按预期创建的,但它从未通过onComplete方法,我做错了什么?
答案 0 :(得分:0)
我认为没有必要将task.isSuccesful()放在已经onComplete()回调中。会要求您尝试以下代码段:
firebaseAuth.createUserWithEmailAndPassword(email, senha)
.addOnCompleteListener(CadastroActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show();
Log.d("SuccessInCreateUser", "No exception");
if (!task.isSuccessful()) {
Log.w(TAG, "onComplete: Failed=" + task.getException().getMessage());
//Catch specific exception here like this. Below is the example of password less than 6 char - weak password exception catch
if (task.getException() instanceof FirebaseAuthWeakPasswordException) {
Toast.makeText(getApplicationContext(), "Weak Password", Toast.LENGTH_SHORT).show();
}
}
});
如果有任何改变,请告诉我。