Question

I am trying to send camera image from one intent to another intent to display. Currently i am trying using the following method,

Once the image captured

     protected void onActivityResult(int requestCode, int resultCode, Intent data) {  

     super.onActivityResult(requestCode, resultCode, data);  
     switch(requestCode)
     {
         case CAMERA_RECEIPTREQUEST:  
         if(resultCode== Activity.RESULT_OK)
         {
         BitmapFactory.Options options = new BitmapFactory.Options();
         options.inSampleSize = 8;
         //ImageView jpgView = (ImageView)findViewById(R.id.imageView1);
         Bitmap receipt = BitmapFactory.decodeFile(photo.toString(),options);  

         Intent imagepass = new Intent(Activity1.this,Activity2.class);
         imagepass.putExtra("imagepass", imagepass);
         startActivity(imagepass);

In second activity

      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.receiptreview);   
        //creating view ids
        createViewIds();  

        Bitmap receiptimage = (Bitmap) getIntent().getExtras().getParcelable("imagepass");
        receipt.setImageBitmap(receiptimage); 
    } 

But it shows StackOverFlow error,

        at java.util.HashMap$EntrySet.iterator(HashMap.java:944)
        at android.os.Parcel.writeMapInternal(Parcel.java:486)
        at android.os.Bundle.writeToParcel(Bundle.java:1552)
        at android.os.Parcel.writeBundle(Parcel.java:502)
        at android.content.Intent.writeToParcel(Intent.java:5477)

I am not sure whether i am trying wrong method.I am looking for some sample or solution to this.

Thank for your help guys.

Was it helpful?

Solution

use

         Bitmap receipt = BitmapFactory.decodeFile(photo.toString(),options);  

         Intent imagepass = new Intent(Activity1.this,Activity2.class);
         imagepass.putExtra("imagepass", receipt );
         startActivity(imagepass);

instead of

        Bitmap receipt = BitmapFactory.decodeFile(photo.toString(),options);  

         Intent imagepass = new Intent(Activity1.this,Activity2.class);
         imagepass.putExtra("imagepass", imagepass);
         startActivity(imagepass);

You are passing Intent instance imagepass in imagepass.putExtra("imagepass", imagepass); so pass Bitmap instance in imagepass.putExtra("imagepass", receipt );

EDIT:

for passing images (bitmaps) between activities in android see these posts:

how do you pass images (bitmaps) between android activities using bundles?

How can I pass a Bitmap object from one activity to another

OTHER TIPS

From what I can see your passing the intent itself to be send. Try:

imagepass.putExtra("imagepass", receipt);

Might work, still new to android myself.

we can try another way to convert the image to byte array and then pass the byte array through intent and in the activity being called we can convert the byte array into bitmap

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top