How to take pic from camera and send image to second activity and in second activity image will be shown on image view.kindly give me the code. i will be very thankful.
-
Have a look at the `putExtra()` method of the class `Intent` – Sebastian Walla May 02 '15 at 15:54
-
Welcome to SO! To be sure to get good and useful answers to your questions, you must ensure that you are providing enough information in your post that describe your problem - even better with a code example of yours! – Hulvej May 02 '15 at 16:04
3 Answers
You should pass the informantion on the Intent
as an Extra
.
An example:
startActivity(new Intent(PresentActivity.this, NextActivity.class).putExtra("Key", "Value"));
More specifically for taking a picture and showing it on an ImageView, use an startActivityForResult
.
Example code:
startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE), REQUEST_CODE);
This will call a new activity which will take a picture, then you'll only need to call the onActivityResult
method on the same activity you called the previous code and handle the result (take the picture uri and set it on the ImageView
).

- 902
- 1
- 10
- 20
Have a look at the putExtra() and the getExtra() method. Here are some code snippets:
//First Acitivity
Bitmap img=//set here the image you got from the camera.
Bundle extras = new Bundle();
extras.putParcelable("image", img);
intent.putExtras(extras);
startActivity(intent);
//Second Activity
Bundle extras = getIntent().getExtras();
Bitmap bmp = (Bitmap) extras.getParcelable("image");
If you didn't already think about, how to start the camera and get the image, I'd suggest you to use startActivityForResult()
.

- 1,104
- 1
- 9
- 23
Bitmap capturedImage = // set your image here
File tempDir = this.getCacheDir();
File tempFile = null;
FileOutputStream fos = null;
try {
tempFile = File.createTempFile("temp", ".png", tempDir);
fos = new FileOutputStream(tempFile);
if (capturedImage.compress(Bitmap.CompressFormat.PNG, 85, fos)) {
fos.flush();
fos.close();
Uri fileUri = Uri.fromFile(tempFile);
result.putExtra("fileUri", fileUri);
this.setResult(Activity.RESULT_OK, result);
this.finish();
} else {
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
you can't put image to intent. intent extra has size limit of 1MB.
just save your image to temp file and send it's uri.

- 33
- 1
- 7
-
I thought the limitation of 1MB would have been fixed http://stackoverflow.com/questions/12496700/maximum-length-of-intent-putextra-method-force-close , like it´s written here? But creating a temp file should work, no matter wether extra has a limit or not – Sebastian Walla May 02 '15 at 16:09
-
@SebastianWalla I can confirm that the 1MB limit is not fixed. I doubt it really won't be fixed either. – DeeV May 02 '15 at 16:14