Pass A Bitmap Between 2 Activities
I've been trying to solve this issue for 2 hours and i haven't found the solution yet. My activity has the option of taking a photo with the camera API or to browse an image from g
Solution 1:
You'd rather pass image URI instead of image data.
In the onActivityResult()
method you can get the image URI:
UriimageUri= data.getData();
Then you can pass this uri to the other activity when starting it:
Intent intent = newIntent(context, MyNextActivity.class);
intent.setData(imageUri);
startActivity(intent);
And in the next activity you can retrieve this URI:
UriimageUri= getIntent().getData();
And then to display the image in an ImageView:
imageView.setImageURI(imageUri);
Solution 2:
Try with this code,
In your FirstActivity,
Bitmapbitmap= BitmapFactory.decodeResource(getResources(), R.drawable.icon);
Intentintent=newIntent();
intent.setClass(AndroidPassingBitmap.this, AndroidReceiveBitmap.class);
intent.putExtra("Bitmap", bitmap);
startActivity(intent);
In SecondActivity,
Bitmapbitmap= (Bitmap)this.getIntent().getParcelableExtra("Bitmap");
ImageViewviewBitmap= (ImageView)findViewById(R.id.bitmapview);
viewBitmap.setImageBitmap(bitmap);
Post a Comment for "Pass A Bitmap Between 2 Activities"