title: Android: Exit application from custom dialog
body: <p>I created a <strong>custom dialog</strong> for my main activity with two buttons, <code>Exit</code> and <code>Continue</code>:</p>
  
  <pre><code>public class AgeConfirmationDialog extends Dialog {
  
      public AgeConfirmationDialog(Activity a) {
          super(a);    
      }
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          setCancelable(false);
          setContentView(R.layout.age_dialog);
          // .....
          // Find the View objects; checkboxes and buttons logic; SharedPreferences
          // .....
      }
      // .....
  }
  </code></pre>
  
  <p>This is how the dialog is launched from the MainActivity:</p>
  
  <pre><code>AgeConfirmationDialog d = new AgeConfirmationDialog(this);
  d.show();
  </code></pre>
  
  <p>This custom dialog pops out every time the main activity is started, and asks for a age confirmation. I don't want the users to close this dialog using the back button, so I added <code>setCancelable(false)</code> in the <code>onCreate</code> method. The <code>Continue</code> button is disabled until a checkbox is checked. If the <code>Continue</code> button is pressed, the dialog is dismissed - using <code>setOnClickListener</code>.</p>
  
  <p>The problem is that I don't know <strong>how to dismiss that custom dialog AND finish the main activity</strong> when the <code>Exit</code> button is pressed.</p>
  
  <p>Is it possible to do this from the <code>AgeConfirmationDialog</code> class by setting a <code>View.OnClickListener</code> on the <code>Exit</code> button?</p>