in tasks/app/src/main/java/com/google/firebase/quickstart/tasks/MainActivity.java [51:106]
public void basicTaskHandlers() {
// [START success_listener]
task.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
// Task completed successfully
// ...
}
});
// [END success_listener]
// [START failure_listener]
task.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// Task failed with an exception
// ...
}
});
// [END failure_listener]
// [START completion_listener]
task.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Task completed successfully
AuthResult result = task.getResult();
} else {
// Task failed with an exception
Exception exception = task.getException();
}
}
});
// [END completion_listener]
// [START listener_try_catch]
Task<AuthResult> signInTask = FirebaseAuth.getInstance().signInWithEmailAndPassword(
"email@example.com", "mypassword1234");
signInTask.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
try {
// Specific error information can be obtained by passing the expected
// exception type into getResult(). In this case we expect a
// FirebaseAuthException based on the documentation,
AuthResult authResult = task.getResult(FirebaseAuthException.class);
} catch (FirebaseAuthException e) {
// Task failed with FirebaseAuthException, which provides specific error
// error information. such as the error code.
String errorCode = e.getErrorCode();
}
}
});
// [END listener_try_catch]
}