Basically: 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 incorrectly calls back to Activity C's onActivityResult method. Note that Activity B.getCallingActivity() returns Activity A, as expected.
In more detail:
I have three Activities:
EditModuleActivity (Activity A)
EditMotorActivity (Activity B)
ConfigurationActivity (Activity C)
Inside of EditModuleActivity (Activity A), I have this 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?");
}
Inside of EditMotorActivity (Activity B), I have this 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();
}
ConfigurationActivity (Activity C) has this in it:
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
}
When I am in EditModuleActivity and I launch EditMotorActivity, ConfigurationActivity.onActivityResult gets called. Instead, When I am in EditModuleActivity and I launch EditMotorActivity, EditModuleActivity.onActivityResult should get called but that's not happening.
Questions
Why is the wrong onActivityResult getting called??
How do I call the right onActivityResult? Is my expectation incorrect? How else does this work?
If the wrong one gets called, how to I call the correct one?
Answers I've seen that didn't help
My code is the same as the accepted answer here: onActivityResult() not being called in activity
I do not have
android:launchMode="singleInstance"in my ManifestI don't know what a "fragment" is but I don't think I have that.
Note that I'm NOT calling two different Activities from one Activity, as in this question: Handling onActivityResult in Android app having more than one activity Instead, I'm calling the SAME activity from two different Activities.
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?? WRONG onActivityResult() being called
Like this:
   B
 /  \
A    C
Not this:
X   Z
 \ /
  Y