title: Managing activity from DialogFragment
body: <p>How can I call finish() and other non static methods from a DialogFragment in the activity that created it? I have tried passing messages from the OnClickLisener in the DialogFragment, to no avail.</p>
  
  <p>I have a really simple app, conssting of a MainActivity and DialogFragment:</p>
  
  <pre><code>    public class MainActivity extends Activity {
  @Override
  protected void onCreate(Bundle arg0) {
      super.onCreate(arg0);
      setContentView(R.layout.activity);
      showDialog();
  }
  public void showDialog() {
      DialogFragment newFragment = new ConfirmDialog();
      newFragment.show(getFragmentManager(), "dialog");
  }
  </code></pre>
  
  <p>}
  And the Dialog is again very simple:</p>
  
  <pre><code>public class ConfirmDialog extends DialogFragment {
  @Override
  public AlertDialog onCreateDialog(Bundle savedInstanceState) {
      // Use the Builder class for convenient dialog construction
      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
      builder.setMessage("Confirm you want to continue?")
             .setPositiveButton("Yes.", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
                     //finish() MainActvity
                    }
                 })
             .setNegativeButton("No.", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
                   //Do nothing in MainActity
                 }
             });
      // Create the AlertDialog object and return it
      return builder.create();
  }
  </code></pre>
  
  <p>}</p>