title: onActivityResult in wrong activity is being called
body: <p><strong>Basically</strong>: Activity A calls startActivityForResult, which launches Activity B. At this point, Activity B SHOULD call back to Activity A's onActivityResult method.  Instead, Activity B then <strong>incorrectly</strong> calls back to Activity C's onActivityResult method. Note that Activity B.getCallingActivity() returns Activity A, as expected.</p>
  
  <p><strong>In more detail:</strong></p>
  
  <p>I have three Activities:</p>
  
  <ul>
  <li><p>EditModuleActivity (Activity A)</p></li>
  <li><p>EditMotorActivity (Activity B)</p></li>
  <li><p>ConfigurationActivity (Activity C)</p></li>
  </ul>
  
  <p>Inside of EditModuleActivity (Activity A), I have this code:</p>
  
  <pre><code>private void launchIntentFromHere(){
      int requestCode = 101;
      Intent editMotorIntent = new Intent(context, EditMotorActivity.class);     
      editMotorIntent.putExtra(EditMotorActivity.EDIT_MOTOR_CONTROLLER, item);
      editMotorIntent.putExtra("requestCode", requestCode);
      setResult(RESULT_OK, editMotorIntent);
      startActivityForResult(editMotorIntent, requestCode);
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      DbgLog.error("*************************** why is this never getting called?");
  }
  </code></pre>
  
  <p>Inside of EditMotorActivity (Activity B), I have this code:</p>
  
  <pre><code>private void doThisThing(Object item){
      // blah blah build intent
      DbgLog.error("calling activity: " + getCallingActivity().toString()); // this prints out Activity A, which is what I expect.
      returnIntent.putExtra(EDIT_MOTOR_CONTROLLER, item);
      setResult(RESULT_OK, returnIntent); 
      finish();
  }
  </code></pre>
  
  <p>ConfigurationActivity (Activity C) has this in it:</p>
  
  <pre><code>private void launchIntent(Object item){
      Intent editMotorIntent = new Intent(context, EditMotorActivity.class);
      editMotorIntent.putExtra(EditMotorActivity.EDIT_MOTOR_CONTROLLER, item);
      setResult(RESULT_OK, editMotorIntent); 
      startActivityForResult(editMotorIntent, 1);
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      // deals properly with the results
  }
  </code></pre>
  
  <p>When I am in EditModuleActivity and I launch EditMotorActivity, <strong>ConfigurationActivity.onActivityResult gets called</strong>. Instead, When I am in EditModuleActivity and I launch EditMotorActivity, EditModuleActivity.onActivityResult should get called but that's not happening.</p>
  
  <p><strong>Questions</strong></p>
  
  <ul>
  <li><p>Why is the wrong onActivityResult getting called??</p></li>
  <li><p>How do I call the right onActivityResult? Is my expectation incorrect? How else does this work?</p></li>
  <li><p>If the wrong one gets called, how to I call the correct one?</p></li>
  </ul>
  
  <p><strong>Answers I've seen that didn't help</strong></p>
  
  <ul>
  <li><p>My code is the same as the accepted answer here: <a href="https://stackoverflow.com/questions/26239761/onactivityresult-not-being-called-in-activity">onActivityResult() not being called in activity</a></p></li>
  <li><p>I do not have <code>android:launchMode="singleInstance"</code> in my Manifest</p></li>
  <li><p>I don't know what a "fragment" is but I don't think I have that.</p></li>
  <li><p>Note that I'm NOT calling two different Activities from one Activity, as in this question: <a href="https://stackoverflow.com/questions/7262405/handling-onactivityresult-in-android-app-having-more-than-one-activity">Handling onActivityResult in Android app having more than one activity</a> Instead, I'm calling the SAME activity from two different Activities.</p></li>
  <li><p>A comment here says "If you call activity B from class A, it will always return codes to the class A That's the same if you call D from C." But I calling Activity B from Activity B and it returns to Activity C. WHY?? <a href="https://stackoverflow.com/questions/24479770/wrong-onactivityresult-being-called">WRONG onActivityResult() being called</a></p></li>
  </ul>
  
  <p>Like this:</p>
  
  <pre><code>   B
   /  \
  A    C
  </code></pre>
  
  <p>Not this:</p>
  
  <pre><code>X   Z
   \ /
    Y
  </code></pre>