转型前的片段暂时可见

时间:2017-05-18 21:54:01

标签: android android-fragments

我正在使用带有活动的片段:

CameraActivity:

public void onPictureTaken(byte[] data, Camera camera) {
    int rotation = getPhotoRotation();
    // Note: Do not send large bitmap images in Bundles and it will lead to Failed Binder Transaction
    // Use CachePot to pass large data
    CachePot.getInstance().push(data);

    getFragmentManager()
            .beginTransaction()
            .replace(
                    R.id.fragment_container,
                    EditSavePhotoFragment.newInstance(rotation, mImageParameters.createCopy()),
                    EditSavePhotoFragment.TAG)
            .addToBackStack(null)
            .commit();

    setSafeToTakePhoto(true);
}

CameraFragment:

  Uri photoUri = ImageUtility.savePicture(getActivity(), bitmap);

  ((CameraActivity) getActivity()).returnPhotoUri(photoUri);

EditSavePhotoFragment:

return PhotoUri

startActivityForResult使用CameraFragment调用另一项活动。在新活动开始之前, public void returnPhotoUri(Uri uri) { ... startActivityForResult(intent, REQUEST_CODE); // we will start a fresh capture. getSupportFragmentManager().popBackStack(null, getSupportFragmentManager().POP_BACK_STACK_INCLUSIVE); return; } 在转换之前暂时可见。

InputField

最后,在onActivityResult方法中,我完成了CameraActivity。

如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

我刚才发现问题出在returnPhotoUri:

public void returnPhotoUri(Uri uri) {
    ...
    startActivityForResult(intent, REQUEST_CODE);

    // we will start a fresh capture.
    -- Fix is to use EditSavePhotoFragment.TAG instead of null
    getSupportFragmentManager().popBackStack(EditSavePhotoFragment.TAG, getSupportFragmentManager().POP_BACK_STACK_INCLUSIVE);

    return;
  }