OnActivityResult does not call and the fragment is closed from the selection of Android images

Hi, I know that there are so many questions related to this, but still I can not find the right way :(

I read this link onActivityResult is not called in the Fragment , but I can not find a solution.

              Intent intent = new Intent();
              intent.setType("image/*");
              intent.setAction(Intent.ACTION_GET_CONTENT);
              startActivityForResult(Intent.createChooser(intent, ""),
                                    PICK_IMAGE);


        public void onActivityResult(int requestCode, int resultCode, Intent data) {
                super.onActivityResult(requestCode, resultCode, data);
                if (resultCode != Activity.RESULT_CANCELED) {
                    if (requestCode == PICK_IMAGE && data.getData() != null) {
                        imagePath = getAbsolutePath(data.getData());

                        imageLoader.loadImage("file://" + imagePath,
                                new ImageLoadingListener() {

                                    @Override
                                    public void onLoadingStarted(String imageUri,
                                            View view) {

                                    }

                                    @Override
                                    public void onLoadingFailed(String imageUri,
                                            View view, FailReason failReason) {

                                    }

                                    @Override
                                    public void onLoadingComplete(String imageUri,
                                            View view, Bitmap loadedImage) {
                                        height = loadedImage.getHeight();
                                        width = loadedImage.getWidth();
                                        if (Utils
                                                .validateImageSize(height, width,
                                                        getActivity(),
                                                        "Image size must be in 480 (width) & 800 (height)    with PNG or JPG format"))
                                            imageLoader.displayImage("file://"
                                                    + imagePath, ivSubmitImgWord,
                                                    options);
                                    }

                                    @Override
                                    public void onLoadingCancelled(String imageUri,
                                            View view) {
                                    }
                                });

                    }
                }

            }

when I select an image from the gallery, sometimes onActivityResult is not a call, but the fragment is close. Please someone can help me solve this problem.

+4
source share
2 answers

You need to delete super.onActivityResult(requestCode, resultCode, data);in your fragment and override

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {}
0
source

, noHistory=true . onActivityResult

0

All Articles