AlertDialog's setCancelable(false) method not working

Is this your complete code? then please change your code for setting setCancelable(false) like this

void showDialog() {
    DialogFragment newFragment = MyAlertDialogFragment.newInstance(
            R.string..alert_dialog_two_buttons_title);
    newFragment.setCancelable(false);
    newFragment.show(getFragmentManager(), "dialog");
}

Your dialog is set to no-cancelable, but your host fragment is still cancelable. Set your fragment with setCancelable(false).


Another working example:

Step 1

Create class:

public class DialogActivity extends android.app.DialogFragment {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setMessage(R.string.myMessage);
        setCancelable(false);
        return builder.create();
   }
}

Step 2

Add method to your Activity:

private boolean showDialog() {
    FragmentManager manager = getFragmentManager();
    DialogActivity dialogActivity;
    dialogActivity = new DialogActivity();
    dialogActivity.show(manager, "DialogActivity");
    return true;
}

Step 3

Call showDialog() when you need to show dialog