I have the question about using the AsyncTask with the ProgressDialog.There is the exception after I call the dismiss method. I have find many related questions about this and The answer is “Put it in PostExecute()”. However it does not work…
public class Testing2 extends Activity {
private static final int PROGRESS = 0x1;
private ProgressBar mProgress;
private int mProgressStatus = 0;
private ProgressDialog dialog;
private Handler mHandler = new Handler();
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.done);
mProgress = (ProgressBar) findViewById(R.id.progressbar);
new Testing().execute(1,2,3);
}
private class Testing extends AsyncTask<Integer, Integer, Integer> {
protected void onPreExecute()
{
ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage("dasdasd");
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.show();
}
protected Integer doInBackground(Integer... urls) {
Integer totalSize = 1;
return totalSize;
}
protected void onProgressUpdate(Integer... progress) {
}
protected void onPostExecute(Integer result) {
dialog.dismiss();
}
}
}
You are assigning ProgressDialog to a local variable and not to the field
dialogSo instead of
use
If you are not doing much in doinbackground, i doubt the progressbar will show up. If you want to test the functionality, atleast put a sleep call for 2 seconds in doinbackground