Suppose if you have a questions like below image in firebase database.
database = FirebaseFirestore.getInstance();
ArrayList<Question> questions;
String categoryId = getIntent().getStringExtra("categoryId");
database.collection("categories")
.document(categoryId)
.collection("Questions")
.get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
for(DocumentSnapshot snapshot : queryDocumentSnapshots) {
Question question = snapshot.toObject(Question.class);
questions.add(question);
}
Collections.shuffle(questions);
}
});
In my case, I have a category (for example computer category, software category) and in each category we have a collection of questions Therefore we get a specific categoryId to display questions of specific category.
first you get all the question from database and add in a list like questions.add(question);
if all the added in a list then you shuffle the questions in the list, Collections.shuffle(questions);
so each time you get different questions.