public class CreateAccountActivity extends AppCompatActivity {
private EditText emailedittxt;
private EditText passwordedittext;
private Button signUp;
//private EditText nametext;
private static final String TAG = "EmailPassword";
//Authentication
private FirebaseAuth mAuth;
// public static Intent newIntent(Context packageContext){
// Intent intent = new Intent(packageContext,CreateAccountActivity.class);
// return intent;
// }
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_account);
mAuth = FirebaseAuth.getInstance();
// nametext = (EditText) findViewById(R.id.RnameText);
emailedittxt = (EditText) findViewById(R.id.RemailText);
passwordedittext = (EditText) findViewById(R.id.RpasswordText);
signUp = (Button) findViewById(R.id.RsignupButton);
signUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// signUp();
//create new Account
// String name = nametext.getText().toString();
String email = emailedittxt.getText().toString();
String password = passwordedittext.getText().toString();
//validate the felids
// if (TextUtils.isEmpty(name)) {
// Toast.makeText(CreateAccountActivity.this, "Enter your nmae", Toast.LENGTH_SHORT).show();
// return;
// }
if (TextUtils.isEmpty(email)) {
Toast.makeText(CreateAccountActivity.this, "Enter your email", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(CreateAccountActivity.this, "Enter your password", Toast.LENGTH_SHORT).show();
return;
}
/*Create
new account */
SignUp(email,password);
}
});
}
private void SignUp(String email,String password) {
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(CreateAccountActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());
// // Toast.makeText(CreateAccountActivity.this, "createUserWithEmail:onComplete:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// // signed in user can be handled in the listener.
if (task.isSuccessful()) {
Intent intent = new Intent (CreateAccountActivity.this,Main2Activity.class);
startActivity(intent);
// startActivity(new Intent(CreateAccountActivity.this, Main2Activity.class));
finish();
} else {
Log.d(TAG, "onComplete: Failed=" + task.getException().getMessage()); //ADD THIS
//
//// Toast.makeText(CreateAccountActivity.this, "Authentication failed." + task.getException(), Toast.LENGTH_SHORT).show();
}}
});
}
}
任何人都知道为什么它永远不会运行onComplete()
答案 0 :(得分:0)
尝试添加onFailureListener()
:
private void SignUp(String email,String password) {
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(CreateAccountActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());
// // Toast.makeText(CreateAccountActivity.this, "createUserWithEmail:onComplete:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// // signed in user can be handled in the listener.
if (task.isSuccessful()) {
Intent intent = new Intent (CreateAccountActivity.this,Main2Activity.class);
startActivity(intent);
// startActivity(new Intent(CreateAccountActivity.this, Main2Activity.class));
finish();
} else {
Log.d(TAG, "onComplete: Failed=" + task.getException().getMessage()); //ADD THIS
//
//// Toast.makeText(CreateAccountActivity.this, "Authentication failed." + task.getException(), Toast.LENGTH_SHORT).show();
}}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e("exception",e.getMessage());
}
});
}