1

I recently came across a code snippet that used Runnable with AsyncTask, which I was not familiar with previously.

  AsyncTask.execute{

   /* Some code to run in Background
    * ...
    * ...
    */

   runOnUiThread{
     //run on main thread, just like onPostExecute
   }

 }

I would like to know how does this compare with following way where we create an AsyncTask class?

    class MyAsyncTask : AsyncTask<Unit, Unit, String>() {
        override fun doInBackground(vararg params: Unit): String {...}
        override fun onPostExecute(result: String) {...}
    }

Are there any performance or other downsides of the first method?

hasn
  • 749
  • 6
  • 21

1 Answers1

0

I don't think it has any thing to do with performance. They are just different ways that you could use to implement this action. If I was writing this code, I would create a class and implement it there.

hasn
  • 749
  • 6
  • 21
Nima Mohammadi
  • 353
  • 2
  • 9