AsyncTask and AsyncTaskLoader
AsyncTask and AsyncTaskLoader
AsyncTask and AsyncTaskLoader
Background
Tasks
Lesson 7
● Threads
● AsyncTask
● Loaders
● AsyncTaskLoader
● AsyncTask
● The Loader Framework
● Services
Worker Thread Do some work
Worker Thread
doInBackground()
● onProgressUpdate()
○ Runs on the main thread
○ receives calls from publishProgress() from background thread
doInBackground()
doInBackground()
doInBackground()
onProgressUpdate()
doInBackground(
onPostExecute()
● String—could be query, URI for filename
● Integer—percentage completed, steps done
● Bitmap—an image to be displayed
● Use Void if no data passed
AsyncTask and This work is licensed under a Creative
Android Developer Fundamentals V2 Commons Attribution 4.0 International 17
AsyncTaskLoader
License.
onPreExecute()
LoaderManager
Request Receive
Work Result
Activity
AsyncTask and This work is licensed under a Creative
Android Developer Fundamentals V2 Commons Attribution 4.0 International 31
AsyncTaskLoader
License.
AsyncTask AsyncTaskLoader
doInBackground() loadInBackground()
onPostExecute() onLoadFinished()
1. Subclass AsyncTaskLoader
2. Implement constructor
3. loadInBackground()
4. onStartLoading()
@Override
public Loader<List<String>> onCreateLoader(int id, Bundle args) {
return new StringListLoader(this,args.getString("queryString"));
}
@Override
public void onLoaderReset(final LoaderList<String>> loader) { }