Implementing a simple AsyncTask
Let's get into the details now. We will show you the following through source code:
- How to extend
AsyncTask
- How to pass constructor arguments
- What methods to override
- How to set up a progress dialog through the
preexecute()
method - Where to do the actual work: the
doInBackground()
method - How to trigger progress callbacks
- How to override the progress method to report progress
- How to detect the end of work through the
postExecute()
method
We will start with how to extend AsyncTask
as it uses generics and is worth spending a few minutes on.
GettingPpast the Generics in AsyncTask
The AsyncTask
class employs generics to provide type safety to its methods. AsyncTask
(through generics) wants you to specify the following ...
Get Pro Android 4 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.