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?

4

1 回答 1

0

我认为这与性能无关。它们只是您可以用来实现此操作的不同方式。如果我正在编写这段代码,我会创建一个类并在那里实现它。

于 2019-05-25T07:56:54.907 回答