You need to set the ProgressDialog
as cancelable (true) .
progressBar.setCancelable(true);
setCancelable
sets whether this dialog is cancelable with the BACK
key
If you need to close the Activity
when the Progress dialog dismiss
on BACK
key, add a listener like this and finish
the Activity
.
progressBar.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
finish();
}
});
Since OnDismissListener
will get invoked in general on all dialog dismiss
conditions , you can set OnCancelListener
which only be invoked only when the dialog is cancelled
progressBar.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
finish();
}
});