title: How to use Thread.sleep() in Kotlin
body: <p>This comes from near the end of the codelab found here:</p>
  <p><a href="https://developer.android.com/codelabs/basic-android-kotlin-training-intro-debugging?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-four%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-intro-debugging#5" rel="noreferrer">Intro to debugging - Debugging example: accessing a value that doesn't exist</a></p>
  <p>This is all inside the MainActivity.kt file</p>
  <p>Here's my onCreate</p>
  <pre><code>class MainActivity : AppCompatActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_main)
      val helloTextView: TextView = findViewById(R.id.division_textview)
      helloTextView.text = &quot;Hello, debugging!&quot;
  
      division()
  }
  //...
  </code></pre>
  <p>Here's the division function provided by Google, but with 2 changes I'll explain in a moment...</p>
  <pre><code>fun division() {
    val numerator = 60
    var denominator = 4
      repeat(4) {
       Thread.sleep(3000)
       findViewById&lt;TextView&gt;(R.id.division_textview).setText(&quot;${numerator / denominator}&quot;)
       Log.v(TAG, &quot;${numerator / denominator}&quot;)
       denominator--
      }
    }
  </code></pre>
  <p>The instructions make it seem like they expect <code>sleep()</code> to accept seconds, but AS indicates it expects millis, so I changed their 3 to 3000. I added <code>Log.v(TAG, &quot;${numerator / denominator}&quot;)</code> to see what was happening because it wasn't doing as expected.</p>
  <p>The point of this was to have the emulator create a gif of the quotients being updated. This is supposed to be helpful when debugging.</p>
  <p>Nothing displays on screen, not even the app's name, until the <code>repeat()</code> finishes.
  The logs happen in 3 second intervals, as expected.</p>
  <p>Why is the layout waiting, and how do I make it update on each iteration of the loop?</p>