If you are using AlertDialog, see
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// dialog dismiss without button press
}
});
and dialog.setCanceledOnTouchOutside(true) (thanks @LeosLiterak)