Professional Documents
Culture Documents
7.1 AsyncTask and AsyncTaskLoader
7.1 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
This work is licensed under a Creative
Android Developer Fundamentals AsyncTask Commons Attribution-NonCommercial 17
4.0 International License
onPreExecute()
LoaderManager
Request Receive
Work Result
Activity
This work is licensed under a Creative
Android Developer Fundamentals AsyncTask Commons Attribution-NonCommercial 31
4.0 International 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) { }