title: How to get the Data from DialogFragment to MainActivity in Android?
body: <p>I create a application using <code>DialogFragment</code>.I want to get the Data from <code>DialogFragment</code> and <code>setText</code> in the <code>MainActivity</code>. In my Code I successfully Created the <code>AlertDialog</code>.But I con't able to get the <code>EditText</code> value to <code>MainActivity</code>.Application is crashed.Please help me to solve the problem.Any Help would be I really Appreciate.</p>
  
  <p><code>MainActivity.java</code> :</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  Button showDialog;
  TextView showText;
  String myNameStr;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      showDialog = (Button)findViewById(R.id.myBtn);
      showText = (TextView)findViewById(R.id.showText);
      showDialog.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              showMyAlert(v);
          }
      });
  }
  
  public void showMyAlert(View view) {
      MyAlert myAlert = new MyAlert();
      myAlert.show(getFragmentManager(), "My New Alert");
  }
  
  public void setMyNameStr(String myNameStr) {
      showText.setText(myNameStr);
  }
  }
  </code></pre>
  
  <p><code>MyAlert.java</code>:</p>
  
  <pre><code>public class MyAlert extends DialogFragment implements OnClickListener {
  private EditText getEditText;
  MainActivity callBackActivity;
  
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
  
      callBackActivity = new MainActivity();
      getEditText = new EditText(getActivity());
      getEditText.setInputType(InputType.TYPE_CLASS_TEXT);
      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
      builder.setTitle("Get UserName :");
      builder.setMessage("Enter Your Name :");
      builder.setPositiveButton("Ok", this);
      builder.setNegativeButton("Cancel", null);
      builder.setView(getEditText);
      return builder.create();
  }
  
  @Override
  public void onClick(DialogInterface dialog, int which) {
      String value = getEditText.getText().toString();
      Log.d("Name : ", value);
      MainActivity mainActivity = new MainActivity();
      mainActivity.setMyNameStr(value);
      dialog.dismiss();
  }
  }
  </code></pre>
  
  <p>Using this Procedure Application is Crashed.</p>