So I have an app with a button that opens the camera, takes a picture, and then shows it on screen. But I don't how to make it show up in a different activity. Help would be very much appreciated. I have had this problem for two weeks, and nothing I tried has worked.
Asked
Active
Viewed 41 times
-2
-
1This will definitely help you. https://stackoverflow.com/a/5991757/2470770 – lib4backer Jan 02 '18 at 15:55
-
"I have had this problem for two weeks, and nothing I tried has worked." - Could you elaborate on this please? What have you tried and what hasn't worked? – PPartisan Jan 02 '18 at 15:56
1 Answers
0
I'd strongly suggest passing the image across the Intent as a file (unless it is very small, in which case you could send the bitmap as an extra with intent.putExtra("data", bitmap)
).
This method, in your camera activity, saves the image to a file:
public void saveImageToFile(Bitmap bmp) {
String fn = "sent_image";
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
FileOutputStream fo = openFileOutput(fn, Context.MODE_PRIVATE);
fo.write(bytes.toByteArray());
fo.close();
}
Then use an intent to switch activities.
Intent intent = new Intent(this, YourSecondActivity.class);
startActivity(intent);
In your other activity:
Bitmap bitmap = BitmapFactory.decodeStream(context.openFileInput("sent_image"));
ImageView iv = (ImageView) findViewById(R.id.yourImageViewID);
iv.setImageBitmap(bitmap);
where context
is either this
or getActivity()
in a fragment

Pinico
- 74
- 1
- 1
- 8