2

Activity 1:I have an imageview in which the images taken from camera and gallery are set and it works fine. In this Activity there is a right click button which will redirect you to second activity.

Activity 2: In this Activity I have four options

  1. Save
  2. Share
  3. Share Via Instagram
  4. Share Via Facebook

Activity 3: From the above four options the third activity works accordingly. Now I don't know how to pass the image taken in first activity to the third activity.

My Effort: In first Activity image taken from camera:

 Intent i=new Intent(Camera.this,SaveVia.class);
 i.putExtra("image", thumbnail );
 startActivity(i);

In Second Activity SaveVia:

Intent intent2 = new Intent(SaveVia.this, Save.class);
Bitmap receiptimage = (Bitmap)getIntent().getExtras().getParcelable("image")
startActivity(intent2);

In third Activity called Save:

Bitmap receiptimage = (Bitmap) getIntent().getExtras().getParcelable("imagepass");
       // receipt.setImageBitmap(receiptimage);
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        receiptimage.compress(Bitmap.CompressFormat.PNG, 90, bytes);
        File storagePath = new File(Environment.getExternalStorageDirectory() + "/PhotoAR/");
        storagePath.mkdirs();

        File destination = new File(storagePath, Long.toString(System.currentTimeMillis()) + ".jpg");

        FileOutputStream fo;
        try {
            destination.createNewFile();
            fo = new FileOutputStream(destination);
            fo.write(bytes.toByteArray());
            fo.close();
            Toast.makeText(Save.this,"No Error",Toast.LENGTH_LONG).show();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            Toast.makeText(Save.this,"Error Arrived",Toast.LENGTH_LONG).show();
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(Save.this,"Error Arrived again",Toast.LENGTH_LONG).show();
Aastha Doshi
  • 147
  • 1
  • 14
  • try to Use Interface... – Gowthaman M Nov 11 '17 at 05:14
  • 1
    Please look at this. [link] (https://stackoverflow.com/questions/4352172/how-do-you-pass-images-bitmaps-between-android-activities-using-bundles). It's a duplicate of your question. Also, as in the linked question it isn't a good idea to actually pass images using parcelable. You would be better of passing a path of the image to your second and third activities and then pull up the image using the path.This would be a much simpler approach. :) – imaadhrizni Nov 11 '17 at 05:22
  • Possible duplicate of [how do you pass images (bitmaps) between android activities using bundles?](https://stackoverflow.com/questions/4352172/how-do-you-pass-images-bitmaps-between-android-activities-using-bundles) – imaadhrizni Nov 11 '17 at 05:22

2 Answers2

2

@AND You don't need to pass bitmap as Parcelable from one activity.Pass file path in intent from one activity to another.

When you capture image get path in onActivityresult and save that path. And redirect that two second activity.And from that path show your bitmap.Just Share Uri from path in share on facebook and Instagram.

Nirav Shah
  • 263
  • 3
  • 12
1

I recommend using File I/O to save the bitmap to disk. Put the path of the file into your intent bundle using putExtra and recreate the bitmap in your other screens. Putting large bitmaps into a bundle with an intent can cause TransactionTooLarge exceptions.

Take a look at Getting path of captured image in android using camera intent

Marc
  • 219
  • 1
  • 15