Skip to content Skip to sidebar Skip to footer

What Is The Difference Between Loader Or AsyncTask?

I want to know the difference between Android loader and AsyncTask , here the demo on Loader: package com.android.loaderdemo; import org.json.JSONArray; import org.json.JSONObject

Solution 1:

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.


Solution 2:

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 .


Post a Comment for "What Is The Difference Between Loader Or AsyncTask?"