Asynctask vs Thread vs Services vs Loader

前端 未结 6 1755
你的背包
你的背包 2020-12-04 14:55

I got slightly confused about the differences between Asynctask, Thread, Service, Loader in Android.

I know how

6条回答
  •  攒了一身酷
    2020-12-04 15:10

    It doesn't really matter, what abstraction you use, it boils down to a Thread. So each of Android's async/parallel classes are using Thread/Executor behind the scenes, and have exactly the same potential problems, like locking, that the threads have.

    The difference between then lies in its' usage. AsyncTask for example, defines a handy completion-callback - onPostExecute(). A CountDownTimer allows you to control the time and so on.

    You can use a plain Thread of course, but in this case you have to invest more time in catching possible problems yourself.

    So, Android provides you with a couple of right tools for right jobs.

提交回复
热议问题