【发布时间】:2012-08-22 14:49:58
【问题描述】:
在我的应用程序中,我有一个列表视图,每个项目都有一个按钮。如果用户单击按钮,我想执行一些 http 连接。所以我在 Adapter 类中使用 AsyncTask。现在的问题是进度对话框没有显示。
private class MyClass extends AsyncTask<Void, Long, Boolean> {
private Context context;
private ServerCall call = new ServerCall();
private ProgressDialog progressDialog1;
public MyClass(Context context) {
this.context = context;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
try {
progressDialog1 = ProgressDialog.show(context, "",
"Please wait...", true);
progressDialog1.setIndeterminate(true);
} catch (final Throwable th) {
}
}
@Override
protected void onProgressUpdate(Long... values) {
super.onProgressUpdate(values);
}
@Override
protected Boolean doInBackground(Void... params) {
//some tasks
return true;
}
@Override
protected void onPostExecute(Boolean result) {
if (mode.equalsIgnoreCase("History")) {
Intent order = new Intent(context, ActicityA.class);
order.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(order);
} else {
Intent order = new Intent(context, ActivityB.class);
order.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(order);
}
}
}
【问题讨论】:
-
是否调用了 onPreExcute() 方法?我们需要铁道部信息。
-
@LazyNinja 是 onPreExcute() 调用。我在 lagcat 看到它
-
为什么不在 preExecute 方法内的 catch 块中记录异常。如果您在那里遇到异常,您就会知道问题所在。
标签: android android-asynctask android-adapter android-context