Reputation: 965
I was going through vogella's tutorial and i can across this:
private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
I am not sure what this void means and why is it being used ?
Upvotes: 0
Views: 49
Reputation: 2504
See AsyncTask javadoc :
Not all types are always used by an asynchronous task. To mark a type as unused, simply use the type
Void
:
private class MyTask extends AsyncTask<Void, Void, Void> { ... }
Void in generics simply means that your parameterised class will use void wherever this generic is used (generally for return value).
Upvotes: 0
Reputation: 1155
Void used there means that you are not going to publish results before async task finish.
Upvotes: 1
Reputation: 213411
Let's go through the documentation of AsyncTask
:
The three types used by an asynchronous task are the following:
- Params, the type of the parameters sent to the task upon execution.
- Progress, the type of the progress units published during the background computation.
- Result, the type of the result of the background computation.
Not all types are always used by an asynchronous task. To mark a type as unused, simply use the type
Void
:private class MyTask extends AsyncTask<Void, Void, Void> { ... }
Void
is just a type argument, similar to how you give Integer
, Float
, etc.
Upvotes: 2
Reputation: 48272
The second parameter goes into onProgressUpdate()
. In case you do not want to make progress update notifications you pass Void
as the second parameter and do not implement onProgressUpdate()
Upvotes: 1