title: How can I have OnCompleteListener wait in Kotlin?
body: <p>I call the <code>getFavorite</code> method to get data from the Database Class in Activity. But It doesn't wait for <code>onCompleteListener</code>. So The list comes as empty. What should I do?</p>
  
  <p><strong>GetMovieActivity.java</strong></p>
  
  <pre><code>    private fun getPhotoListFromApi() {
      val apiService = ApiClient.getRetrofitInstance().create(ApiService::class.java)
  
      var list = ArrayList&lt;MovieDetailsResponse&gt;()
      var db = Database()
      db.getFavorite()
  
      for (id in db.moviesID)
      {
          apiService.getMovieDetails(
                  id.toString().toInt(),
                  "922df43f1a304aca901feb9728b01943",
                  Locale.getDefault().language + "-" + Locale.getDefault().country)
                  .enqueue(object : Callback&lt;MovieDetailsResponse&gt; {
  
                      override fun onFailure(call: Call&lt;MovieDetailsResponse&gt;, t: Throwable) {
                      }
  
                      override fun onResponse(call: Call&lt;MovieDetailsResponse&gt;, response: Response&lt;MovieDetailsResponse&gt;) {
                          response.body()?.let { it -&gt;
  
                              list.add(it)
                          }
  
                      }
  
                  })
  
      }
      adapter.setList((list as List&lt;MovieListItem&gt;?)!!)
  
  }
  </code></pre>
  
  <p><strong>Database.kt</strong></p>
  
  <pre><code>    fun getFavorite()
  {
     val dr = db.collection("Favorites").document(mAuth!!.uid) as DocumentReference
      dr.get().addOnCompleteListener { task: Task&lt;DocumentSnapshot&gt; -&gt;
          if(task.isSuccessful)
          {
              moviesMap = task.result.data!!
              moviesID = moviesMap.get("movies") as ArrayList&lt;Any&gt;
          }
      }
  
  }
  </code></pre>