Currently running fragment closes and gets back into previous activity when trying to import photo from gallery and set it to ImageView.
I want to set the imported image to an ImageView which is in the fragment. But when I select the image it closes the current fragment and goes back to the previous activity.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK) {
if(requestCode == 1000){
try {
Uri returnUri = data.getData();
Bitmap bitmapImage = null;
bitmapImage = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), returnUri);
ImageView iv = getView().findViewById(R.id.profile_image);
iv.setImageBitmap(bitmapImage);
getFragmentManager().popBackStackImmediate();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
I want choose an image from the gallery and set it to an ImageView which is in the currently running fragment without getting closing it.
I tried putting getFragmentManager().popBackStackImmediate(); in OnActivityResult() in my fragment. But it doesn't work.