Override onUserLeaveHint() and finish/kill your activity/process accordingly.
E.g.,
@Override
public void onUserLeaveHint() {
finish();
super.onUserLeaveHint();
}
UPDATE
Create a local boolean variable to track the button click that shows the dialog. Set it true as soon as user clicks the button; in all other cases (in onResume()
, once started drawing thread, after returning from the dialog, etc) keep it false. In onPause()
pause the drawing thread only if that variable is true.