title: ADK - User prompt dialog is cancelled/bypassed almost instantly
body: <p>I am attempting to prompt a user for input based on prior input.</p>
  
  <p>Allow me to clarify and add some context:<br>
  This application is a dice-rolling simulator. The main activity displays the number of dice and number of sides on each die, which is changed by opening a sub-activity from the menu. This sub-activity is called for its result using <code>startActivityForResult()</code>, and consists entirely of a <code>RadioGroup</code> and two buttons - "Accept" and "Cancel" - and passes a <code>String</code> extra back to the main activity (in the format "XdN" - e.g. "1d20"), which the main activity then parses and uses to adjust the dice count and side count accordingly.</p>
  
  <p>This system works exceptionally well for examples like "1d6", "1d10", and the like, and is <strong>not</strong> the problem - <em>as far as I know</em>.</p>
  
  <p>Now, here's my problem:<br>
  I have a radio button that passes the <code>String</code> "Custom" (instead of an "XdN"-like <code>String</code>). When selected (and, finally, when "Accept" is clicked), my intention is for a dialog to open and prompt the user for custom count values - and this works, sort of. The dialog shows, and the layout is correct and looks like it should, but <strong>the layout then disappears after a split-second and passes the current count values instead of the values that <em>would</em> have been entered by the user.</strong> This also throws an error to LogCat (I'm using Eclipse and ADT) that says:</p>
  
  <pre><code>Application            Tag             Text
  org.x3chaos.nicedice   WindowManager   Activity org.x3chaos.nicedice.DiceActivity
                                         has leaked window com.android.internal.pol
                                         icy.impl.PhoneWindow$DecorView@44786f20 th
                                         at was originally added here
  org.x3chaos.nicedice   WindowManager   android.view.WindowLeaked: Activity org.x3
                                         chaos.nicedice.DiceActivity has leaked win
                                         dow com.android.internal.policy.impl.Phone
                                         Window$DecorView@44786f20 that was origina
                                         ly added here
  org.x3chaos.nicedice   WindowManager   at android.view.ViewRoot.&lt;init&gt;(ViewRoot.j
                                         ava:247)
  
  [more if needed]
  </code></pre>
  
  <p>--</p>
  
  <p>The <code>Button</code> <em>button_accept</em>'s <code>android:onClick</code> method follows:</p>
  
  <pre><code>public void accept(View view) {
  
      RadioGroup group = (RadioGroup) findViewById(R.id.dice_radiogrp);
      RadioButton selected = (RadioButton) findViewById(group
              .getCheckedRadioButtonId());
      String tmpResult = selected.getText().toString();
  
      if (!tmpResult.matches("[0-9|xX](.*)[Dd][0-9](.*)")) {
  
          // Show dialog
  
          LayoutInflater li = LayoutInflater.from(this);
          View dialogView = li.inflate(R.layout.prompt_dice, null);
  
          AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setView(dialogView);
          builder.setTitle("Custom Dice");
          builder.setCancelable(false);
  
          final EditText editCount = (EditText) findViewById(R.id.edit_promptDiceCount);
          final EditText editSides = (EditText) findViewById(R.id.edit_promptDiceSides);
  
          builder.setPositiveButton("Accept", new OnClickListener() {
  
              @Override
              public void onClick(DialogInterface dialog, int which) {
  
                  boolean flag = false;
                  String textCount, textSides;
                  textCount = editCount.getText().toString();
                  if (textCount.equals("")) {
                      textCount = "1";
                      flag = true;
                  }
                  textSides = editSides.getText().toString();
                  if (textSides.equals("")) {
                      textSides = "20";
                      flag = true;
                  }
  
                  int count = Integer.parseInt(textCount);
                  int sides = Integer.parseInt(textSides);
  
                  if (count &gt; 20)
                      count = 20;
                  if (sides &gt; 20)
                      sides = 20;
  
                  String finRes = count + "d" + sides;
  
                  setResultExtra(finRes);
  
                  if (flag) {
                      String msg = "Invalid input: set dice to " + finRes;
                      Toast toast = Toast.makeText(context, msg,
                              Toast.LENGTH_SHORT);
                      toast.show();
                  }
  
              }
  
          });
  
          builder.setNegativeButton("Cancel", new OnClickListener() {
  
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  dialog.cancel();
                  exitActivity(false);
              }
  
          });
  
          AlertDialog dialog = builder.create();
          dialog.show();
  
      } else {
          result = tmpResult;
      }
  
      exitActivity(true);
  
  }
  </code></pre>
  
  <p>All other functions work, so I'm not sure why this isn't. I'm sure it's something that I'm messing up - seeing as this is my first app and I'm using some objects and methods that I've never touched before - so I really appreciate any help. :]</p>
  
  <p><strong>EDIT:</strong> After reading <a href="https://stackoverflow.com/questions/6336930/android-dialog-disappears-on-its-own">this question</a>, I'm starting to think that maybe it's an <code>Intent</code> that's not waiting for the dialog to finish. But this doesn't quite make sense, since the activity that calls the dialog is called for a result.</p>