I also had a problem. In fact, the callback for startActivityForResult() returns to the parent activity, so you need to make an explicit call from the fragment to the onActivityResult() function as follows.
In the Parent Activity class, override the onActivityResult() method and even override it in the fragment class and call it as the following code.
In the parent class:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Fragment fragment = getFragmentManager().findFragmentById(R.id.container); fragment.onActivityResult(requestCode, resultCode, data); }
In the kids class: This Extends snippet follows your logic for adjusting the image in image view.
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (data != null) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getActivity().getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String picturePath = cursor.getString(columnIndex); image.setImageBitmap(BitmapFactory.decodeFile(picturePath)); cursor.close(); } else { Toast.makeText(getActivity(), "Try Again!!", Toast.LENGTH_SHORT).show(); } super.onActivityResult(requestCode, resultCode, data); }
source share