Reputation: 81
I am a beginner Android programmer. Trying to use AsyncTask and ProgressDialog but encountered a problem -- the ProgressDialog is unable to be dismissed.
The following codes are inside an importExportActivity which extends 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;
}
}
Done a lot of google search but can't seem to find a solution to this.
Can someone help?
Upvotes: 0
Views: 2437
Reputation: 81
Answering my own question. The following worked:
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;
}
}
Upvotes: 1
Reputation: 5531
I think you are not returning :
@Override
protected void onPostExecute(final Void success) {
dialog1.dismiss();
return;
}
Upvotes: 2
Reputation: 8647
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);
}
mine is working this way ...
Upvotes: 0