Android: RunOnUiThread vs AsyncTask

前端 未结 5 1049
渐次进展
渐次进展 2020-12-01 00:50

I believe Google suggests developers to use AsyncTask. However, I would like to know how is it different from using \'new Thread\' and then calling \'RunOnUiThread\' in perf

5条回答
  •  鱼传尺愫
    2020-12-01 01:20

    It's a convenience, essentially. The AsyncTask framework deals with managing the Thread pool and provides a simple, understandable interface. It's well-known -- by those that know how to use AsyncTask -- that UI activity can go on in onPreExecute(), onPostExecute() and onProgressUpdate(), and that all of the "heavy lifting" is done in doInBackground() where you can't touch the UI.

    It makes it easy for a developer to have a simple background task that can easily post updates to the UI thread and return results when done. It's not magic, it's just a convenience.

提交回复
热议问题