I have been using this AsyncTask for couple of projects, but still don't quite get what does <String, Void, String>
mean. Do these mean the parameter types of the unimplemented methods? are there any orders(what are the method corresponds to String, Void, String respectively)?

- 7,367
- 19
- 54
- 80
-
http://stackoverflow.com/questions/13238150/java-generics-what-is-this-syntax-for – David M Nov 26 '12 at 12:52
3 Answers
From Android Docs AsyncTask page:
android.os.AsyncTask<Params, Progress, Result>
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.
Now my understanding in simple words:
Params: (in your case String) is the parameter that the AsyncTask
takes. You have to pass this when you call execute
method
Progress: (in your case Void) is the type of progress. Void means you are not using it. If it is say, Integer, you could've used values like 10, 20, 30... and use these to show a progress bar on screen.
Result: (in your case String) is what the AsyncTask
returns as the result. You are returning a String. You can return any Object you want.
So simply put, it is somewhat like a method where Params are parameters, Result is return type and progress tells you status of processing progress.
For further understanding see this tutorial, also quote from the same page may be helpful:
AsyncTask<TypeOfVarArgParams, ProgressValue, ResultValue>
TypeOfVarArgParams is passed into the doInBackground() method as input, ProgressValue is used for progress information and ResultValue must be returned from doInBackground() method and is passed to onPostExecute() as parameter.

- 1
- 1

- 6,630
- 5
- 34
- 49
It's described in docs:
android.os.AsyncTask<Params, Progress, Result>
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.
If you do not need one of these, pass Void
(but there're always have to be 3 types)

- 72,056
- 11
- 123
- 141
Ist parameter in AsyncTask refers to the parameter to be passed in doInBackground, 2nd parameter is to be passed in onProgressUpdate and 3rd parameter is to be passed in onPostExecute. We can use any data type suitable as per functionality. An example for a call with parameter type (String, Integer , String) is given below.
private class MyTask extends AsyncTask<String, Integer, String>
{
protected String doInBackground(String... u)
{
// do something in background
return null;
}
protected void onPreExecute()
{
// do something before start
}
public void onProgressUpdate(Integer... args)
{
}
protected void onPostExecute(String result)
{
// do something after execution
}
}

- 1,377
- 10
- 14