4

Hi I know there is so much question related to this but still i can not find right way :(

I read this link onActivityResult is not being called in Fragment but i can not find the 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 choose image from gallery sometimes onActivityResult is not call and Fragment is close.please anybody can help me to solve this problem.

Community
  • 1
  • 1

2 Answers2

0

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

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {}
Gowtham Kumar
  • 534
  • 8
  • 22
0

check if you have noHistory=true set on your manifest for the activity. This will not call onActivityResult

Irshu
  • 8,248
  • 8
  • 53
  • 65