title: Run a function in its entirety before moving to next activity
body: <p>I want to click a button, which will pull some data from Firebase, then I want to go to the next activity, passing an array that contains the Firebase data. I still can't wrap my head around asynchronous code, and I was hoping someone could help me out with the simplest way to accomplish this. </p>
  
  <p>I've experimented with runblocking, suspend functions, await and async, but I can't seem to get it right. Here's my on click listener:</p>
  
  <pre><code>btn_games_quiz.setOnClickListener {
  
      listenForQuestions()
  
      val intent = Intent(this, QuizActivity::class.java)
      intent.putExtra("questionArray", questionArray)
      startActivity(intent)
  
  }
  </code></pre>
  
  <p>And here's listenForQuestions:</p>
  
  <pre><code>private fun listenForQuestions(){
  
      val current = LocalDateTime.now()
      val formatter = DateTimeFormatter.ofPattern("MM")
      val formatted = current.format(formatter)
      val currentMonth = QuizActivity.months[formatted.toInt()]
  
      val ref = FirebaseDatabase.getInstance().getReference("/quizzes/$currentMonth")
  
      ref.addChildEventListener(object: ChildEventListener {
  
          override fun onChildAdded(p0: DataSnapshot, p1: String?) {
                  val questionItem = p0.getValue(Question::class.java)
  
                  if (questionItem != null) {
                      questionArray += questionItem
                  }
          }
  
          override fun onCancelled(p0: DatabaseError) {
          }
  
          override fun onChildChanged(p0: DataSnapshot, p1: String?) {
          }
  
          override fun onChildMoved(p0: DataSnapshot, p1: String?) {
          }
  
          override fun onChildRemoved(p0: DataSnapshot) {
          }
      })
  
  }
  </code></pre>
  
  <p>A point in the right direction would be greatly appreciated.</p>