I have an activity A that calls an activity B (FragmentActivity) using startActivityForResult()
. Before activity B finishes by calling finish()
, I use setResult()
. In spite of all of this, onActivityResult()
is not called. I'm not sure what I'm doing wrong as I'm not doing anything unconventional, or if this is an Android bug.
Seeing some of the suggestions on here, I've checked to see that I don't have android:launchMode="singleInstance"
nor android:noHistory="true"
set anywhere in my manifest file.
Calling activity B from A:
Intent intent = new Intent(getActivity(), ActivityB.class);
startActivityForResult(intent, MY_RESULT);
Finishing activity B:
Intent intent = new Intent();
setResult(Activity.RESULT_OK, intent);
finish();
Overriding onActivityResult()
in activity A:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
Toast.makeText(getApplication(), "toast", Toast.LENGTH_LONG).show();
}
Edit 1
I commented out nearly all of activity B's code (see below), leaving A's intact and the problem remained. So, A is definitely doing something strange that causes the problem. Worse, I have done this with other activities (using the same code) without any problems! A extends ExpandableListActivity
, although I don't understand how any of that code would cause issues in onActivityResult()
. Logcat isn't giving me anything useful.
This is the code tested for activity B, for posterity's sake (though it seems to be that the problem is in A):
public class ActivityB extends FragmentActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_activityb);
Intent intent = new Intent();
intent.putExtra("data", "Hello from ActivityB");
setResult(Activity.RESULT_OK, intent);
finish();
}
}