我想介绍一下Firebase / firestore中所有失败的案例。我见过函数会触发OnFailure回调,但是在什么情况下会触发OnCanceled?我无法为各种功能(例如写入/删除以及对FirebaseUser和AuthUI的操作)强制使用OnCanceled()触发器,也没有看到任何文档。这些病例在某处有记录吗?
FirebaseDatabase.getInstance().getReference("users/test").setValue("blabla")
.addOnSuccessListener(new OnSuccessListener<Void>()
{
@Override
public void onSuccess(Void aVoid)
{
Log.v("TEST", "DB WRITE SUCCESS");
}
})
.addOnFailureListener(new OnFailureListener()
{
@Override
public void onFailure(@NonNull Exception e)
{
Log.v("TEST", "DB WRITE FAILURE " + e);
}
})
.addOnCanceledListener(new OnCanceledListener()
{
@Override
public void onCanceled()
{
Log.v("TEST", "DB WRITE CANCELLED");
}
});
FirebaseFirestore fs = FirebaseFirestore.getInstance();
fs.collection("users").document("blabla").set(data)
.addOnSuccessListener(new OnSuccessListener<Void>()
{
@Override
public void onSuccess(Void aVoid)
{
Log.v("TEST", "FS WRITE SUCCESS");
}
})
.addOnFailureListener(new OnFailureListener()
{
@Override
public void onFailure(@NonNull Exception e)
{
Log.v("TEST", "FS WRITE FAILURE " + e);
}
})
.addOnCanceledListener(new OnCanceledListener()
{
@Override
public void onCanceled()
{
Log.v("TEST", "FS WRITE CANCELLED");
}
});
FirebaseUser user = mAuth.getCurrentUser();
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName(name)
.build();
user.updateProfile(profileUpdates)
.addOnSuccessListener(new OnSuccessListener<Void>()
{
@Override
public void onSuccess(Void aVoid)
{
Log.v("NICK", "SUCCESS UPDATED PROFILE");
}
})
.addOnCanceledListener(new OnCanceledListener()
{
@Override
public void onCanceled()
{
Log.w("NICK", "CANCELED UPDATE PROFILE");
}
})
.addOnFailureListener(new OnFailureListener()
{
@Override
public void onFailure(@NonNull Exception e)
{
Log.w("NICK", "FAILED TO UPDATE PROFILE");
}
});
AuthUI.getInstance().delete(this)
.addOnSuccessListener(new OnSuccessListener<Void>()
{
@Override
public void onSuccess(Void aVoid)
{
Log.v("AUTHUI", "SUCCESS DELETED ACCNT");
}
})
.addOnCanceledListener(new OnCanceledListener()
{
@Override
public void onCanceled()
{
Log.w("AUTHUI", "CANCELED DELETE ACCNT");
}
})
.addOnFailureListener(new OnFailureListener()
{
@Override
public void onFailure(@NonNull Exception e)
{
Log.w("AUTHUI", "FAILED TO DELETE ACCNT " + e);
}
});
答案 0 :(得分:1)
在什么情况下会触发OnCanceled?
不是。任务取消仅发生在专门设计为可取消的任务上。 Firestore任务不会发生这种情况。