title: Kotlin thread status different state in fragment
body: <p>My goal is to update IU elements in a thread in Fragment (when it is visible). Basically I've got a thread that is supposed to run in loop. It checks if one of UI element is not null, or else terminates.</p>
  <pre><code>private val thread = Thread {
    while (txtHomeDest != null) {
      txtHomeDest.post { txtHomeDest.text = something }
      ...
      Thread.sleep(50)
    }
  </code></pre>
  <p>I start the thread in onStart or in onViewCreated. According to documentation only NEW thread can be started so I have a check:</p>
  <pre><code>override fun onStart() {
    super.onStart()
    println(thread.state)
    if (thread.state == Thread.State.NEW) thread.start()
  }
  </code></pre>
  <p>Above method is working only if I open the fragment directly from it's UI button. In that case the above code in line &quot;println(thread.state)&quot; prints state NEW and everything is working as expected. But when I go to another fragment and click the back button, then I got state TERMINATED and new thread cannot be started. To start thread I have to click once again on UI element that opens that fragment. I hope it make sens, because it's hard for me to explain :) How to use threads correctly in this case ?</p>