Declaring AsyncTask types
AsyncTask
is a generically typed class that exposes three generic type parameters:
abstract class AsyncTask<Params, Progress, Result>
In order to use a generic type, we must provide one type argument per type parameter that was declared for the generic type.
Note
The generic type class provides a way to re-use the same generic algorithms for different input types. A generic type could have one or more type parameters.
When we declare an AsyncTask
subclass, we'll specify the types for Params, Progress, and Result; for example, if we want to pass a String
parameter to doInBackground
, report progress as a Float
, and return a Boolean
result, we would declare our AsyncTask
subclass as follows:
public class MyTask extends AsyncTask<String, ...
Get Asynchronous Android Programming - Second Edition 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.