【发布时间】:2020-09-04 11:47:41
【问题描述】:
我正在尝试创建几个 Java 类来执行某些工作。假设我想通过这样调用我的类来完成任务:
FirebaseAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithCredential:success");
FirebaseUser user = task.getResult().getUser();
// ...
} else {
// Sign in failed, display a message and update the UI
Log.w(TAG, "signInWithCredential:failure", task.getException());
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
// The verification code entered was invalid
}
}
}
});
我最多可以理解 signInWithCredential()。我不知道如何实现 addOnCompleteListener() 并将接口作为参数。
我目前使用 getInstance () 和 signInWithCredential() 等方法创建了我的顶级类,例如 FirebaseAuth。另外,我尝试创建一个接口,但我收到错误,即接口的结果从未使用过。如何实现addOnCompleteListener(参数1,接口2)的样式。
在这里,addOnCompleteListener 正在获取活动和接口的参数,就我而言,我将使用活动参数进行一些工作。
P.S:我发现这叫做接口回调。如果它是正确的,任何关于它的结构的指导都会很棒
【问题讨论】: