How to set AlertDialog.finish() in the AlertDialog?
<p>I am currently using an app that needs to utilize a lot of AlertDialogs. I've currently coded a basic one here:</p>

<pre><code>protected void StopButton () {
    AlertDialog.Builder StopDialog = new AlertDialog.Builder(MainActivity.this);
    StopDialog.setTitle(R.string.Stop_Title);
    StopDialog.setMessage(R.string.Stop_Message);
    StopDialog.setPositiveButton(R.string.Yes_Button, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            ((Protoype2) getApplication()).setRequestingLocationUpdates(false);
            finish();
        }
    });
    StopDialog.setNegativeButton(R.string.No_Button, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            ((Protoype2) getApplication()).setRequestingLocationUpdates(true);
        }
    });
    StopDialog.setNeutralButton(R.string.Negative_Button, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            //Closes box
            finish();
        }
    });
    AlertDialog alert = StopDialog.create();
    alert.show();
}
</code></pre>

<p>The StopButton works and the Dialog comes up when I call for it. However, the finish(); function does not work.</p>

<p>Upon review, I found that finish(); did not finish the Dialog, rather the entire app. I know I need to get a AlertDialog.cancel in there.</p>

<p>The problem is this: as you can see, the AlertDialog is only created AFTER the StopDialog is finished.</p>

<p>How can I set an AlertDialog.finish() before StopDialog is finished?</p>