1

First fragment from which image is selected

           iv.setImageURI(Uri.fromFile(pictureFile));
                String stringUri;
                stringUri = pictureFile.toString();

                FreeFragment ldf = new FreeFragment ();
                Bundle args = new Bundle();
                args.putString("Image", stringUri);
                ldf.setArguments(args);
                Log.d("Passing image", String.valueOf(args));
                getFragmentManager().beginTransaction().add(R.id.container, ldf).commit();

Second fragment receiving image and displaying it

 String bbb = getArguments().getString("Image");
    Bitmap bitmap = BitmapFactory.decodeFile(bbb);
    iv.setImageBitmap(bitmap);
Sivakumar S
  • 129
  • 2
  • 3
  • 16

3 Answers3

7

Send file path to next Fragment

String stringUri = pictureFile.getAbsolutePath();

FreeFragment ldf = new FreeFragment ();
Bundle args = new Bundle();
args.putString("Image", stringUri);
ldf.setArguments(args);

getFragmentManager().beginTransaction().add(R.id.container, ldf).commit();

In your NextFragment u can receive it and set as below

String imgPath = getArguments().getString("Image");
Bitmap bitmap = BitmapFactory.decodeFile(new File(imgPath));
iv.setImageBitmap(bitmap);
kevz
  • 2,727
  • 14
  • 39
1

Try getting your bundle in second fragment like this

    Bundle bundle = this.getArguments();
if (bundle != null) {
    String s = bundle.getString(key, defaulValue);
}

Also check this link for further references Passing bundle in fragments

Community
  • 1
  • 1
Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84
0
Bundle bundle = this.getIntent().getExtras();
String strPic = bundle.getString("Image");
File picFile = new File("your file path"+strPic);
if(picFile.exists())
{           
   iv.setImageURI(Uri.fromFile(picFile));
}           
Htoo Aung Hlaing
  • 2,173
  • 15
  • 26