title: How to close app if user presses back button on dialog
body: <p>I am new to Android and developing a utility UI component which displays dialog box on launch , I want to close the app if user does not make a choice in the dialog box and chooses to press back button. How do I achieve this in dialogFragment? I would not have access to the activity code .</p>
  
  <p>This component is implemented as DialogFragment.</p>
  
  <p>I tried  </p>
  
  <pre><code>    dialog.setOnDismissListener( new OnDismissListener()
      {
          @Override
          public void onDismiss(DialogInterface dialog)
          {
              getActivity().finish();
          }
      });
  </code></pre>
  
  <p>but this does not close the activity if I press back button.</p>
  
  <p>what is the best practice to implement mandatory dialog box in Android</p>
  
  <p>Thanks in advance</p>