I want to returning True or False when document in collections is exists or not. But it's always return false.
if (checkItemDeleted(post)) {
// true, item still there
} else {
// false, item deleted
}
boolean result = false;
private boolean checkItemDeleted(Post post) {
mPostsCollection
.document(post.itemID)
.get()
.addOnCompleteListener(task -> {
if (task.isSuccessful()){
if (task.getResult().exists()) {
// document exists
result = true;
} else {
// document not exists
result = false;
}
}
});
return result;
}
I'm still learning, thanks for help.