I'm working on the functionality for my app where I send user input to Firestore. When I add an onCompleteListener to collectionReference.add(myObj), I get a Task<DocumentReference>:
collectionReference.add(userObj).addOnCompleteListener(new OnCompleteListener<DocumentReference>() {
@Override
public void onComplete(@NonNull @org.jetbrains.annotations.NotNull Task<DocumentReference> task) {
if(task.isSuccessful()) {
}
}
});
However, when I add an onSuccessListener, I get a DocumentReference:
collectionReference.add(userObj).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(@NonNull @org.jetbrains.annotations.NotNull DocumentReference documentReference) {
}
});
I've read this post: How do I know whether to use OnComplete or OnSuccess? but all I really got from it is that onCompleteListener's don't check if a task has failed or not, so you have to say: if(task.isSuccessful){//do stuff}
What are the differences between Task<DocumentReference> and DocumentReference? How are onSuccess and onCompleteListener's different in Firebase, and when should I use either?
Finally, considering that an onCompleteListener just requires extra work of testing whether the task is successful or not, why would I use an onCompleteListener rather than an onSuccessListener in Firebase?
Thank you!