I have an AsyncTask that shows a progressDialog whilst working (it calls runOnUiThread from within doInBackground to show the progress dialog).
<
Please follow this, it shows the cancel button only async and finish will call by clicking on cancel button
protected void onPreExecute() {
dialogx.setMessage("Loading... Please Wait...");
dialogx.setCancelable(false);
dialogx.setButton(DialogInterface.BUTTON_NEGATIVE,
"Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialogx.dismiss();
GetDataTask.this.cancel(true);
finish();
}
});
dialogx.show();
}