I'm facing a situation where I want to retrieve field values(timings) and store them in sorted order in an ArrayList to process them later on. There are 24 values in my document(00-23). I want to store values at indexes in ascending order as the loop iterates e.g. Value of 00 should be stored at timesList(0) and 23 should be stored at timesList(23). But loop runs much faster than firebase code and I am receiving values in a disordered manner.
final DocumentReference docRef = db.collection("parent").document(child);
docRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
for(int tcounter=0;tcounter<24;tcounter++){
if(tcounter<10){
documentSnapshot.getString("0"+String.valueOf(tcounter));
timesList.add(documentSnapshot.getString("0"+String.valueOf(tcounter)));
}
else{
documentSnapshot.getString(String.valueOf(tcounter));
timesList.add(documentSnapshot.getString(String.valueOf(tcounter)));
if(tcounter==23){
valuesdownloaded="yes";
}
}
}
}
});