Skip to content Skip to sidebar Skip to footer

Alert Dialog Disappers

Alert Dialog disappears when the back button is clicked. Does no give me the opportunity to make a selection. This dialog is suppose to pop up when m == null || m.getPosition() ==

Solution 1:

You have to check in this place with debug mode

if(m == null || m.getPosition() == null)

here only the problem.

Solution 2:

first of all You are checking wrong condition see

if(m == null || m.getPosition() == null)

1. if m is null then the second condition will throw NullPointerException as you are calling getPosition() on a null object.

  1. You are using ||(Or) in If condition with (m==null) check, which is totally wrong .

First you make it right the If statement then the following code will work in your scenario.

new AlertDialog.Builder(this)
                .setTitle("Really Exit?")
                .setMessage("Are you sure you want to exit, without creating a marker?")
                .setNegativeButton(android.R.string.no, null)
                .setCancelable(false)
                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    publicvoidonClick(DialogInterface dialog, int whichButton) {

                    }
                }).show();

To check Marker in your scenario its better to create a method like this one :

private boolean isMarkerAvailable() {
    if (m == null)
        returnfalse;
    elseif (m.getPosition() == null)
        returnfalse;
    returntrue;
}

 if (!isMarkerAvailable()) {
        // Show your alert here or you can toggle // the condition whatever is apropriate in your scenario
    }

Post a Comment for "Alert Dialog Disappers"