【发布时间】:2020-09-01 07:25:43
【问题描述】:
我正在制作一个登录用户可以创建另一个帐户的应用,因此在此代码中,另一个用户已经登录,检查 toast 以查看代码执行的顺序。
btnCreateCompany.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
firebaseAuth.createUserWithEmailAndPassword(txtCompanyEmail.getText().toString(), txtCompanyPassword.getText().toString())
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Toast.makeText(getApplicationContext(), "THIS TOAST IS COMING UP SECOND", Toast.LENGTH_SHORT).show();
if (!task.isSuccessful())
Toast.makeText(getApplicationContext(), "SOMETHING WENT WRONG", Toast.LENGTH_SHORT).show();
else {
Toast.makeText(getApplicationContext(), "THIS TOAST IS COMING UP THIRD", Toast.LENGTH_SHORT).show();
FirebaseUser userCreated = task.getResult().getUser();
userCreated.sendEmailVerification();
userID = userCreated.getUid();//userID is a private field
}
}
}); //After reaching the third toast the code adter onComplete doesn't execute anymore
if (userID == null)
Toast.makeText(getApplicationContext(), "THIS TOAST IS COMING UP FIRST", Toast.LENGTH_SHORT).show();
else {
companyRef = db.collection("companyData").document(userID); (...) }
【问题讨论】:
标签: android firebase google-cloud-firestore firebase-authentication