I know that the Firestore is based on A-sync functions. However, I am trying to retrieve a list and use it outside the function.
private List<CategoriesModel> ourLists(){
List<CategoriesModel> categoriesModels = new ArrayList<CategoriesModel>();
db.collection("categories")
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
CategoriesModel cat = new CategoriesModel(document.toObject(CategoriesModel.class));
categoriesModels.add(cat);
}
Log.d(TAG, categoriesModels.toString());
} else {
Log.d(TAG, "Error getting documents: ", task.getException());
}
}
});
Log.d("end", categoriesModels.toString());
return categoriesModels;
}
How do I wait for the given call and use the data that is inside the "void" function?