我是初学者Android程序员。尝试使用AsyncTask和ProgressDialog但遇到问题 - ProgressDialog无法被解雇。
以下代码位于importExportActivity中,它扩展了Activity -
public class ProgressTask extends AsyncTask<Void, Void, Void> {
ProgressDialog dialog1 = new ProgressDialog(importExportActivity.this);
protected void onPreExecute() {
this.dialog1.show(importExportActivity.this, "",
"Please wait for few seconds...", true);
}
@Override
protected void onPostExecute(final Void success) {
dialog1.dismiss();
}
protected Void doInBackground(final Void ... args) {
...... did the main logic ....
return null;
}
}
完成了很多谷歌搜索,但似乎无法找到解决方案。
有人可以帮忙吗?
答案 0 :(得分:2)
我认为你没有回来:
@Override
protected void onPostExecute(final Void success) {
dialog1.dismiss();
return;
}
答案 1 :(得分:1)
回答我自己的问题。以下工作:
public class ProgressTask extends AsyncTask<Void, Void, Void> {
ProgressDialog dialog1;
protected void onPreExecute() {
dialog1 = ProgressDialog.show(importExportActivity.this, "",
"Please wait for few seconds...", true);
}
@Override
protected void onPostExecute(final Void success) {
dialog1.dismiss();
}
protected Void doInBackground(final Void ... args) {
...... did the main logic ....
return null;
}
}
答案 2 :(得分:0)
protected void onPreExecute() {
this.dialog1.show(importExportActivity.this, "",
"Please wait for few seconds...", true);
super.onPreExecute();
}
@Override
protected void onPostExecute(final Void success) {
dialog1.dismiss();
super.onPostExecute(RESULT);
}
我正在这样工作......