【发布时间】:2012-11-05 13:25:35
【问题描述】:
我想将我想启动的类作为参数发送,因为这个异步任务想用来启动不同的活动。
例子:
.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
new taskIntent().execute(**example1.class**);
}
}
.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
new taskIntent().execute(**example2.class**);
}
}
private class taskIntent extends AsyncTask<String, Integer, Void> {
ProgressDialog dialog;
@Override
protected Void doInBackground(String... params) {
return null;
}
@Override
protected void onPreExecute() {
dialog = ProgressDialog.show(Calendar.this, "",
"Loading...", true);
dialog.show();
}
protected void onPostExecute(Void unused){
Intent intent = new Intent(Calendar.this, **parameter[0]**);
startActivity(intent);
finish();
dialog.dismiss();
}
}
如何将类作为参数发送以在意图中使用它?
谢谢,抱歉我的英语不好
【问题讨论】:
-
一,Class != String
-
另外,鉴于您的 doInBackground 什么都不做,我看不出 AsyncTask 的意义
-
我需要 Asynctask 使用进度对话框,直到它加载其他类
-
除非你在 doInBackground 中做某事,否则你不需要异步任务
标签: android android-intent android-asynctask