0

I am creating a AlertDialog and it is being dismissed even when dismiss() is not called. The code is as below :

public static void noInternetDialog(final Context context) {

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(R.string.alert_title);
    builder.setMessage(R.string.internet_not_available);
    builder.setCancelable(false);
    builder.setPositiveButton(R.string.retryBtnLabel, new AlertDialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            Toast.makeText(context, "Retry Clicked", Toast.LENGTH_SHORT).show();



        }
    });

    builder.setNegativeButton(R.string.alert_negative,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Toast.makeText(context, "Settings Clicked", Toast.LENGTH_SHORT).show();

                }
            });


    AlertDialog alertDialog = builder.create();
    alertDialog.setCancelable(false);
    try {
        alertDialog.show();
    } catch (Exception ignored) {
    }
}

I don't want the dialog to be dismissed in some cases so i am having trouble because it is being dismissed.

bhaskar
  • 991
  • 1
  • 15
  • 37

1 Answers1

0

when you set setPositiveButton or setNegativeButton to AlertDialog.Builde

when positive button or NegativeButton of the dialog is pressed the dialog will automatically dismissed

AskNilesh
  • 67,701
  • 16
  • 123
  • 163