title: How do I loop through items in an array and still be able to interact with other buttons and UI elements in android studio
body: <p>I'm trying to loop through items in an array and log the index of each item every few seconds when a button is pressed.</p>
  <p>Whenever the button is pressed, I can't press other buttons or interact with the screen in any way until it's done looping through all the items.</p>
  <p>How do I make this task run in the background so I can interact with other elements on the screen?</p>
  <pre><code>for(wallpaperUUID in p0.children){
      var wallpaperUUIDString = wallpaperUUID.key.toString()
      var indexOfImage: Int = wallpaperArray.indexOf(wallpaperUUIDString)
  
      Log.i(&quot;Index of Image&quot;, indexOfImage.toString())
  
       val time = measureTimeMillis {
           runBlocking {
                for(i in 1..100000) {
                     launch {
                          delay(2000L)
                     }
                 }
           }
       }
  }
                  
  
  </code></pre>