I have a hierarchy like this in my android app.
ProfileActivity
SettingTabFragment
- ProfileContentFragment
From inside ProfileContentFragment I call another activity called ProfileVideoRecordingActivity using startActivityForResult()
Here is the code in ProfileContentFragment
Intent videoRecordIntent = new Intent(mActivity, ProfileVideoRecordingActivity.class);
startActivityForResult(videoRecordIntent, REQUEST_CODE_PROFILE_VIDEO_PATH);
Here is how I return from ProfileVideoRecordingActivity
Intent intent = new Intent();
intent.putExtra(VIDEO_PROFILE_PATH, renamedVideoFile.getAbsolutePath());
setResult(Activity.RESULT_OK, intent);
//Go back to calling Activity
finish();
Problem is neither ProfileActivity's nor ProfileContentFragment's onActivityResult() is called.
ProfileActivity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
}
SettingTabFragment
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
}
ProfileContentFragment
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == REQUEST_CODE_PROFILE_VIDEO_PATH){
if(resultCode == Activity.RESULT_OK) {
String profileVideoPath = data.getExtras().getString(ProfileVideoRecordingActivity.VIDEO_PROFILE_PATH);
Log.d("DEBUG", profileVideoPath);
}
}
}
I tried solutions from stackoverflow where I need to call fragment's onActivityResult explicitly from activity but that didn't work. Here is what I tried.
ProfileActivity inside onActivityResult()
List<Fragment> fragments = getSupportFragmentManager().getFragments();
if (fragments != null) {
for (Fragment fragment : fragments) {
fragment.onActivityResult(requestCode, resultCode, data);
}
}
SettingTabFragment inside onActivityResult()
List<Fragment> fragments = getChildFragmentManager().getFragments();
if (fragments != null) {
for (Fragment fragment : fragments) {
fragment.onActivityResult(requestCode, resultCode, data);
}
}
Both of them didn't work. What can I do?