I have two fragments FragmentA and FragmentB. I open FragmentB from FragmentA. In FragmentB I take the picture from camera and when I accepted picture, fragment which opened is FragmentA.
I open both fragemnt with replace.
code to repleace fragment
private void replaceFragment(Fragment newFragment, String tag) {
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.replace(R.id.fragment_container, newFragment, tag).addToBackStack(null).commit();
}
create picture
public void btnAddPhoto() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
REQUEST_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
code to receive picture
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode,resultCode,data);
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bitmap imageBitmap = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(imageBitmap);
}
}
I would to stay with FragemntB because i want to set the picture from camera on view in FragemntB. At the moment it looks like FragemntA is upper than FrgamentB, then I return, opened is FragemntB, and at least FragmentA again.