Handle progressdialog in AsyncTask
<p>Using the following code which cancels the AsyncTask when the user clicks on the BACK key of the mobile device.</p>

<pre><code>protected class UploadFiles extends AsyncTask&lt;String, String, String&gt; implements OnDismissListener {

private ProgressDialog mDialog;

protected void onPreExecute() {

super.onPreExecute();
mDialog = new ProgressDialog(UploadFiles.this);
mDialog.setMessage(progressMsg);
mDialog.setCancelable(true);
mDialog.setOnDismissListener(this);
mDialog.show();

}

protected String doInBackground(String... params) {

........
........

}

public void onDismiss(DialogInterface dialog) {

this.cancel(true);
}

protected void onCancelled() {

cancel(true);

}
</code></pre>

<p>The above implementation cancels the AsyncTask when the user clicks on the BACK button of the mobile device.</p>

<p>Since the task is a long time consuming operation , I want to provide the user an alert(warning) whether the user wants to cancel the operation or not ,  when the user clicks the BACK button of the mobile device.</p>

<p>I am not getting the BACK button callback on <strong>onBackPressed()</strong>  when progressdialog is displayed &amp; the user clicks on the back button.</p>

<p>Another issue which I faced in Samsung Tablet P6200 &amp; not in Android emulator:</p>

<p>When the progressdialog is displayed &amp; the user touches the screen outside the progressdialog area ,  the progressdialog dismisses . </p>

<p>How can I stop dismissing the progressdialog ?</p>

<p>Any suggestions/hints for implementing the same will be helpful.</p>

<p>}</p>
