title: Closing multiple Dialogs at once
body: <p>Im writing an Android application in which a user selection triggers a custom <code>Dialog</code>, from which a selection may trigger a second <code>Dialog</code>. </p>
  
  <p>When showing the initial <code>Dialog</code> from the Activity class, I'm setting an <code>onDismissListener</code> on it to pull out user selections which works fine other in cases where the 2nd Dialog is not triggered. The issue that I'm having is that I can't figure out how to have the first one Dialog remain open until the 2nd one is dismissed, so that the information from both is sent back to the Activity class.</p>
  
  <p>Hopefully some code will make this a little more clear:</p>
  
  <p>MainActivity class where I am launching the initial CustomDialog:</p>
  
  <pre><code>customDialog = new CustomDialog(this);
                  customDialog.show();
                  customDialog.setOnDismissListener(new OnDismissListener(){
                      public void onDismiss(DialogInterface di){
                          slection = customDialog.getselection();
                          updateUI(); //updates a listview with the results
                      }
                  });
  </code></pre>
  
  <p>Within the CustumDialog class where I am launching the SecondDialog on top of it:</p>
  
  <pre><code>if(specify){
      SecondDialog secondDialog = new SecondDialog(context);
      secondDialog.show();
      secondDialog.setOnDismissListener( new OnDissmissListener(){
          public void onDismiss(DialogInterface di){
              // this is where I want to call the CustomDialog's dismiss() method
              // so that they both close at the same time and the data from here
              // can be sent back to the MainActiivty through the CustomDialog's
              // onDismissListener
  
          }
      });
  }
  dismiss();
  </code></pre>
  
  <p>So, to reiterate: I'm trying to prevent the CustomDialog's <code>dismiss()</code> method to be called until the SecondDialog is also dismissed. Is there a way that I can call it from the SecondDialog's OnDismissListener?</p>