I have 2 classes, each in separate applications. Activity1 has a button that the user can click, and it invokes the second action using the intent in its onClick() method:
Intent myIntent = getPackageManager().getLaunchIntentForPackage(com.myProject.Activity2); startActivityForResult(myIntent, 600);
This starts Activity2 correctly from Activity1, but onActivityResult is called in Activity1 before onCreate is called in Activity2, not in onBackPressed() , where I set the return intent.
Here is the onCreate method for Activity2:
@Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); }
Here is the current version of the onBackPressed method for Activity2:
@Override public void onBackPressed() { Intent intent = new Intent(); intent.putExtra("Stuff", someStuff); if(getParent()==null){ setResult(Activity.RESULT_OK, intent); }else{ getParent().setResult(Activity.RESULT_OK, intent); } finish(); super.onBackPressed(); }
My AndroidManifest.xml has the following intent filter for Activity2:
<intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter>
I confirmed that my launchMode standard (not singleTask , etc.) is as recommended here , and my request code is not negative, as warned here . I also tried android:launchMode="singleTop" , but that wasn't there either.
I also tried not to call finish() in onBackPressed() for Activity2, as mentioned here (also using only super.onBackPressed() , as suggested here ), and again called it suggested here .
In addition, I tried to comment out the line intent.putExtra("Stuff", someStuff); as it seemed to be causing problems for this person .
Any ideas on what I might be doing wrong?