I'm launching an activity using startActivityForResult() from a button handler, and my onActivityResult() is being called instantly, even before the onCreate() for the target activity is being hit.
public void onGraphNext (View target) {
Intent i = new Intent(this, AddCommentActivity.class);
startActivityForResult(i,6); // 6 is arbitrary request code
}
. . .
protected void onActivityResult(int requestCode, int resultCode,
Intent returnData) {
if ( (resultCode == RESULT_OK) && (requestCode == 6) ) {
Bundle extras = returnData.getExtras();
comment = extras.getString("comment");
}
}
The result code returned is 0 and the request code is 6. Elsewhere on StackOverflow I've seen people report this problem and the solution was to not use singeInstance for the launchMode in the manifest. But I'm using standard . . .
<activity android:name="AddCommentActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:launchMode="standard"></activity>
Thanks in advance for any insights!
EDIT: I made a simple test program and I can reproduce the problem reliably when the caller ("launcher") - the activity with the onActivityResult - is a singleInstance and the Activity being invoked ("launchee") is standard. i.e.,
<activity android:name="Launcher"
android:screenOrientation="portrait"
android:launchMode="singleInstance"></activity>
<activity android:name="Launchee"
android:screenOrientation="portrait"
android:launchMode="standard"></activity>
This is a problem for me because in the real app, the called must be a singleInstance for other reasons, but it wants to have buttons to start up other activities to request user input. How else to do this if I can't use startActivityForResult?