【发布时间】:2020-09-01 00:28:02
【问题描述】:
我正在尝试从名为“photo”的集合中删除一个文档,但它不起作用,没有 OnFailureException 消息,因为显示了 OnSuccess Toast 但该文档仍保留在 Firestore 中:(
这是我用来删除文档的代码:
Photo photo = (Photo) getIntent().getSerializableExtra("photo");
FirebaseFirestore db = FirebaseFirestore.getInstance();
String userId = mAuth.getCurrentUser().getUid();
CollectionReference photoRef = db.collection("main").document(userId).collection("photo");
DocumentReference document = photoRef.document(photo.getId());
String currentDocumentID = document.getId();
photoRef.document(currentDocumentID).delete().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(ViewPhotoActivity.this, "Entry Deleted", Toast.LENGTH_SHORT).show();
startActivity(new Intent(ViewPhotoActivity.this, PhotoActivity.class));
finish();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(ViewPhotoActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
});
【问题讨论】:
标签: android google-cloud-firestore