0

I am pulling information from firestore in android studio, it prints it to the terminal, but I cannot assign or assign the data (int) to the "size" variable, I do not know where I am doing wrong, can anyone help?

var size=0
  authFireStore.collection("xxxColection").document("yyDocument").collection("queryColection").whereEqualTo("Cityname","city").get().addOnSuccessListener { documents ->
                                              for (document in documents) {
                                                    size=documents.size()
                                                    println(documents.size())

                                                }

println("Size :"+size)
Frank van Puffelen
  • 499,950
  • 69
  • 739
  • 734
  • 1
    My guess is that you're trying to use size outside of the success listener, and it is running before the `size=documents.size()` has actually executed. The order in which the log statements show up in your logcat will also show if that's the case. If that is indeed what is happening, that is the expected behavior for Firestore (and most modern cloud APIs) as they load data asynchronously. Any code that needs the data has to be in the completion listener, be called from there, or be otherwise synchronized. – Frank van Puffelen May 16 '22 at 15:37

0 Answers0