【发布时间】:2014-05-23 20:04:34
【问题描述】:
关于主题,正如 google/android 文档所说:
// 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.
我已经使用过几次 AsyncTask 但总是对如何使用它传递/返回参数有一些疑问(通常使用多线程:)。我熟悉 AsyncTask 文档,但想知道我传递上下文/意图参数的方式是否正确,或者我应该使用<Params, Progress, Result>.. 进行此操作:
class CameraStarterTask extends AsyncTask<Void, Void, Void> {
private Context context;
private Intent intent;
public void CameraStarter(Context context, Intent intent) {
this.context = context;
this.intent = intent;
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
return null;
}
}
【问题讨论】:
-
都是一样的。您甚至不能同时多次执行同一个 AsyncTask 实例,因此使用哪种方法来传递参数实际上并没有区别。
-
好的,我为此使用了另一种方法:mHandler.postDelayed(new CameraStarter(context, intent), 7000);
标签: java android multithreading android-asynctask