没有调用onActivityResult。既不是父级也不是嵌套片段

时间:2018-05-10 08:14:06

标签: android android-intent onactivityresult

我的Android应用程序中有这样的层次结构。

  • ProfileActivity

    • SettingTabFragment

      • ProfileContentFragment

从ProfileContentFragment中我使用startActivityForResult()调用另一个名为ProfileVideoRecordingActivity的活动

以下是ProfileContentFragment

中的代码
Intent videoRecordIntent = new Intent(mActivity, ProfileVideoRecordingActivity.class);
                            startActivityForResult(videoRecordIntent, REQUEST_CODE_PROFILE_VIDEO_PATH);

以下是我从ProfileVideoRecordingActivity

返回的方法
Intent intent = new Intent();
intent.putExtra(VIDEO_PROFILE_PATH, renamedVideoFile.getAbsolutePath());
                setResult(Activity.RESULT_OK, intent);

//Go back to calling Activity
finish();

问题既不是ProfileActivity也不是ProfileContentFragment的onActivityResult()被调用。

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);
        }
    }
}

我尝试了stackoverflow的解决方案,我需要从活动中明确地调用片段的onActivityResult,但这不起作用。 这是我试过的。

onActivityResult()

中的ProfileActivity
List<Fragment> fragments = getSupportFragmentManager().getFragments();
    if (fragments != null) {
        for (Fragment fragment : fragments) {
            fragment.onActivityResult(requestCode, resultCode, data);
        }
    }

onActivityResult()

中的SettingTabFragment
List<Fragment> fragments = getChildFragmentManager().getFragments();
    if (fragments != null) {
        for (Fragment fragment : fragments) {
            fragment.onActivityResult(requestCode, resultCode, data);
        }
    }

他们两个都没有用。我该怎么办?

0 个答案:

没有答案