title: Android: Fragment finishes an Activity and onActivityResult is not called
body: <p>I searched and found tons of <code>onActivityResult()/startActivityForResult()</code>  issues, yet I haven't solved my problem.</p>
  
  <p>In my App, I've got a MainActivity which should call a EnterActivity. EnterActivity has two Fragments, a SignupFragment and a LoginFragment. Currently, MainActivity starts EnterActivity with <code>startActivityForResult()</code>, it also overrides the <code>onActivityResult()</code>.</p>
  
  <p>From SignupFragment / LoginFragment, I call <code>getActivity().setResult(...)</code> and <code>getActivity().finish()</code>, which finishes EnterActivity, but <code>MainActivity.onActivityResult()</code> never gets called.
  Can anyone help?</p>
  
  <pre><code>public class MainActivity extends Activity {
      ...
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          if (666 == requestCode) {
              Log.in("gotcha!");
          }
      }
  
      @Override
      protected void onCreate(Bundle bundle) {
          Intent intent = new Intent(this, EnterActivity.class);
          startActivityForResult(intent, 666);
      }
  }
  </code></pre>
  
  <p>The sub-activity looks like this:</p>
  
  <pre><code>public class EnterActivity extends ActionBarActivity {
      ...
      @Override
      protected void onCreate(Bundle bundle) {
          super.onCreate(bundle);
  
          FragmentManager fragmentManager = getSupportFragmentManager();
          fragmentManager.beginTransaction().replace(R.id.main_frame, new LoginFrament())
              .commit();
      }
  }
  </code></pre>
  
  <p>And the Fragment looks like:</p>
  
  <pre><code>public class LoginFragment extends Fragment {
      ...
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
          getView().findViewById(R.id.buttonSignUpLogIn).setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  ...
                  getActivity().setResult(Activity.RESULT_OK);
                  getActivity().finish();
              }
          });
      }
  }
  </code></pre>