execute()向doInBackground()传递。//第1个泛型参数
doInBackground()的返回值会传递给onPostExecute()。//第3个泛型参数
publishProgress()向progressUpdate()传递。//第2个泛型参数
在实例化异步的时候,只需要调用execute(Object... params)方法,就会自动调用doInBackground()并把参数传入。
class MyAsyncTask extends AsyncTask<String, TextView, Double>{
private TextView mTv;
public MyAsyncTask(TextView tv){
this.mTv=tv;
}
@Override
protected Double doInString... params) { < /span>
System.out.println("doInBackground()");
double dou=0;
if (params[0].equals("wei")) {
dou=100;
}
publishProgress(mTv);
return dou;
}
@Override
protectedvoid onPreExecute() {
System.out.println("onPreExecute()");
super.onPreExecute();
}
@Override
protectedvoid onPostExecute(Double result) {
System.out.println("onPostExecute()");
super.onPostExecute(result);
}
@Override
protectedvoid onProgressUpdate(TextView... values) {
System.out.println("onProgressUpdate()");
values[0].setText("bing");
super.onProgressUpdate(values);
}
}
调用
mMyAsyncTask=new MyAsyncTask(tv);
mMyAsyncTask.execute("wei");