0

I have a fragment which shows a list of taken pictures, and allows me to take a new one by clicking a button; however, after taken a picture it goes to a PreviewActivity to accept or cancel the picture taken, and also add a description.

After that, I want to comeback to the fragment with the information. To clarify:

My fragment calls the cameras as below:

imgCamera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(
                        android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                nameFile = UUID.randomUUID().toString().replaceAll("-", "");
                fileName = HelperFoto.createFile(HelperFoto.getTempFile() + date.replace(":", "_"), nameFile + ".jpg");
                intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(fileName.toString())));
                startActivityForResult(intent, 2);
            }
        });

After that, I send the generated data to the PreviewActivity as below:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 2 && resultCode == Activity.RESULT_OK) {

        Intent startPreview = new Intent(getContext(), PreviewActivity.class);
        startPreview.putExtra("path", fileName.toString());
        startActivity(startPreview);

    }

    super.onActivityResult(requestCode, resultCode, data);

}

Therefore, in my PreviewActivity, I was able to retrieve all the necessary information; thus, I can't send it back to the fragment (I tried to use onBackPressed() without success).

Could someone help me?

Tarcisiofl
  • 123
  • 1
  • 4
  • 16

2 Answers2

1

To pass informations between activity and fragment you can Bundle objects

You can have an example of how to use it here : Send data from activity to fragment in android.

Community
  • 1
  • 1
Xema
  • 1,796
  • 1
  • 19
  • 28
0

if you want to load fragment again then you have to follow these steps

FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            HelloFragment hello = new HelloFragment();
            fragmentTransaction.add(R.id.fragment_container, hello, "HELLO");
            fragmentTransaction.commit();
Mrugesh
  • 4,381
  • 8
  • 42
  • 84