How can I kill a custom dialog - before it's been created?
<p>Clearly I have a case of what I like to call "chicken or the egg" syndrome.  I am trying to find a way to kill an alert dialog which isn't created until the end of the process.</p>

<p>What I am trying to do: When asked "Do you want to RE-DOWNLOAD this gallery?", I want to KILL the underlying pop-up (alert/builder) when I get a "Yes" answer.  But not when I get a "No" answer.  In other words, I would like to put an alert.dismiss() in there ... but I can't, because it's not created until the end of the process.</p>

<p>Does that make sense?  I'm racking my brain on this trying to find another way to present this to a user.</p>

<p>Here is my code:</p>

<pre><code>public void showGalleriesDialogue(String galleriesArray) {
Log.v("Status","Ran alert dialogue routine."); 
final CharSequence[] items = TextUtils.split(galleriesArray, "\\^");

final AlertDialog.Builder builder = new AlertDialog.Builder(MainMenu.this);
builder.setTitle("Choose a Gallery to download:");

builder.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int item) {
        final String galleryToDownload = (String) items[item].toString();

        // Check to ensure that this doesn't all ready exist            
        File checkExisists = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/pm-pvault/" + galleryToDownload);
        Log.v("Status","Checking to ensure that '"+checkExisists+"' does not exist."); 
        if(checkExisists.exists()) {
                AlertDialog.Builder existsBuilder = new AlertDialog.Builder(MainMenu.this);
                existsBuilder.setTitle("But wait!");
                existsBuilder.setMessage("This gallery already exists. Do you want to RE-INSTALL it?")
                       .setCancelable(false)
                       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int id) {
                                // Preview stuff, then go get it.
                               GlobalDataStore.retrycount = 0;
                            preview(galleryToDownload);
                               }
                       })
                       .setNegativeButton("No", new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int id) {
                               // Never mind.
                                dialog.cancel();
                           }
                       });
                AlertDialog existsAlert = existsBuilder.create();
                existsAlert.show();
            }
        //OR ELSE
        else 
            if(galleryToDownload.contains("@")==true)  
               {
            AlertDialog.Builder doItNasty = new AlertDialog.Builder(MainMenu.this);
            doItNasty.setTitle("DISCLAIMER");
            doItNasty.setMessage(R.string.nastyDisclaimer)
                   .setCancelable(false)
                   .setPositiveButton("I AGREE", new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {
                            // Download stuff, go get it.
                           GlobalDataStore.retrycount = 0;
                           preview(galleryToDownload);
                       }
                   })
                   .setNegativeButton("DISAGREE", new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {
                           // Never mind.
                           dialog.cancel();
                       }
                   });
            AlertDialog nastyAlert = doItNasty.create();
            nastyAlert.show();
               }
                else {
                    // Out of IF conditions to meet.  Go download it now.
                    GlobalDataStore.retrycount = 0;
                    preview(galleryToDownload);
                    }
            } // END OR ELSE
    }
});
final AlertDialog alert = builder.create();
alert.show();
}
</code></pre>
