私はtasksに直面しており、疑問があります。電子メール/パスの登録後、ユーザーのプロフィールを更新する必要がありました。だから私は、最初にこれを試してみました:特定のパラメータが異なる場合にタスクを正しく続行する方法
FirebaseAuth.getInstance().createUserWithEmailAndPassword(email, password);
.continueWithTask(new Continuation<AuthResult, Task<Void>>() {
@Override
public Task<Void> then(@NonNull Task<AuthResult> t) throws Exception {
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName(fullname)
.build();
return t.getResult().getUser().updateProfile(profileUpdates);
}
})
.addOnFailureListener(this, mOnSignInFailureListener)
.addOnSuccessListener(this, mOnSignInSuccessListener); // <- problem!
問題は私のリスナーがAuthResult
パラメータを待ちますがupdateProfile
タスクはVoid
を送信し、最後の行です。私はそのような状況を蛇腹のように扱いましたが、それはあまりにも面倒です。これを行うには、別のより良い方法があれば教えてください:あなたはmOnSignInSuccessListenerに直接渡さ取得するにはAuthResultを期待しているよう
final Task<AuthResult> mainTask;
mainTask = FirebaseAuth.getInstance().createUserWithEmailAndPassword(email, password);
mainTask
.continueWithTask(new Continuation<AuthResult, Task<Void>>() {
@Override
public Task<Void> then(@NonNull Task<AuthResult> t) throws Exception {
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName(fullname)
.build();
return t.getResult().getUser().updateProfile(profileUpdates);
}
})
.continueWithTask(new Continuation<Void, Task<AuthResult>>() {
@Override
public Task<AuthResult> then(@NonNull Task<Void> t) throws Exception {
return mainTask;
}
})
.addOnFailureListener(this, mOnSignInFailureListener)
.addOnSuccessListener(this, mOnSignInSuccessListener);