package com.boomtech.tremendoustrivia;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.QuerySnapshot;
import java.util.ArrayList;
import java.util.List;
public class DocumentName {
FirebaseFirestore firestore= FirebaseFirestore.getInstance();
public List<String> getDomumentName() {
List<String> docunames=new ArrayList<>();
firestore.collection("Quizquestions").get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
List<DocumentSnapshot> snapshotList = queryDocumentSnapshots.getDocuments();
for (DocumentSnapshot snapshot:snapshotList){
docunames.add(snapshot.getId());
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
return docunames;
}
}
Why this code is returning null? It's not returning the actual List, it's just returning a Null value. How can I get the document's name and pass it to the string of the list so that I can get it whenever I want.