i have a strange problem.
i use nested fragment in my code,( 4 level )
Home -> Services -> ServiceDetails -> Upload
in the last fragment ( Upload Fragment ) i want to choose image from the gallery or the camera so i wrote the following code to pick the image :
switch (which) {
case galleryItem:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(intent, “Select Album”,
Home.GALLERY_REQUEST);
break;
case cameraItem:
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent,
Home.CAMERA_REQUEST);
break;
and every thing is ok.
i can get URI from the selected picture in onActivityResult
of my fragment with the following code:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == Home.GALLERY_REQUEST) {
Uri selectedImageUri = data.getData();
} else if (requestCode == Home.CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
Uri cameraUri = getImageUri(
getActivity().getApplicationContext(), photo);
}
}
}
Problem
if i open my album and scroll ( see all thumbnail ) in that, after selecting my picture onActivityResult
called in the fragment but fragment is not visible any more and Home
fragment ( first fragment ) be visible in my app.
but if i open album ( by startActivityForResult ) and immediately select photo, all thing is going ok.
i don’t any problem with camera.
i searched a lot but don’t find any helpful data, if you want to see any part of my code tell me. i don’t get any crash just i lose my last fragment. thanks in advance.