What is the difference between loader or AsyncTask? [closed]

十年热恋 提交于 2019-12-03 13:34:12
Badrul

From here:

One subclass of Loaders is the AsyncTaskLoader. This class performs the same function as the AsyncTask, but a bit better. It can handle Activity configuration changes more easily, and it behaves within the life cycles of Fragments and Activities. The nice thing is that the AsyncTaskLoader can be used in any situation that the AsyncTask is being used. Anytime data needs to be loaded into memory for the Activity/Fragment to handle, The AsyncTaskLoader can do the job better.

ihsan.gaozp

In my opinion: Loader is better. because I used AsyncTask a year before , that's a really nightmare for me , because you can't control the whole progress immediately , like sometimes , there is also a asynctask run on the activity,but you want to quit the activity ,you should call asynctask.cancel() , but ,this method : cancel() is not cancel the asynctask straightway.so in this case ,you application will crash due to this . so , if you use asynctask , you must be careful about how to cancel the task .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!