title: Without AsyncTask, running a thread in background and updating the UI Thread
body: <p>I was trying to update the recycler view content from a background thread in Kotlin. I am not using AsyncTask.</p>
  
  <p>Here is my code, i want to know if there is any better way than this:</p>
  
  <p>In my MainActivity, i have progressThread as a member variable.</p>
  
  <pre><code> var progressThread = Thread()
  </code></pre>
  
  <p>Then in my method where i want to run the thread first i am defining it...like</p>
  
  <pre><code>        progressThread = Thread (
      Runnable {
          kotlin.run {
              try {
              while (i &lt;= 100 &amp;&amp; !progressThread.isInterrupted) {
                  Thread.sleep(200)
                  //Some Logic
                  runOnUiThread {
                      //this runs in ui thread
  
                  }
                  i++
              }
              }catch (e:InterruptedException){
                  progressThread.interrupt()
              }
          }
      })
  </code></pre>
  
  <p>after that i am starting it in the same method as</p>
  
  <pre><code> progressThread.start()
  </code></pre>
  
  <p>and for stopping it, i have a listener to cancel the progress and in the callback of that listener, i have written:</p>
  
  <pre><code> progressThread.interrupt()
  </code></pre>