How to send image from one activity to another activity?

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.

-------------Problems Reply------------

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).

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)) {
Uri fileUri = Uri.fromFile(tempFile);
result.putExtra("fileUri", fileUri);
this.setResult(Activity.RESULT_OK, result);
} else {

} catch (IOException ioe) {

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.

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);

//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().

Category:android Views:6 Time:2018-04-10
Tags: android

Related post

Copyright (C), All Rights Reserved.

processed in 0.160 (s). 11 q(s)