how to pass captured/gallery image to next activity in android

I want to pass captured camera image and select image from gallery, image should be display in next activity for captured image my code is working fine..but select image from gallery the image is not displaying in the activity..

First Activity

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
     if (resultCode == RESULT_OK) {
        if (requestCode == REQUEST_CAMERA) {

            Uri selectedImage = data.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};

            Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            //file path of captured image
            imagepath = cursor.getString(columnIndex); 
            //file path of captured image
            File f = new File(imagepath);
            String filename = f.getName();

            /*Toast.makeText(Contact.this, "Your Path:"+imagepath, 2000).show();
            Toast.makeText(Contact.this, "Your Filename:"+filename, 2000).show();*/
            //Log.i("image path", imagepath);
            Bitmap imageData = BitmapFactory.decodeFile(imagepath);
            // Bitmap imageData = null;
             imageData = (Bitmap) data.getExtras().get("data");

             Intent i = new Intent(this, Cam.class);
             i.putExtra("name", imageData );

        else if (requestCode == SELECT_FILE) {
                //Bitmap photo = (Bitmap) data.getData().getPath(); 

                Uri selectedImageUri = data.getData();
                imagepath = getPath(selectedImageUri, null);

                 // your bitmap
                //ByteArrayOutputStream bs = new ByteArrayOutputStream();
                Bitmap imageData = BitmapFactory.decodeFile(imagepath);                                                                                               
                imageData = (Bitmap) data.getExtras().get("data");
                Intent intent = new Intent(this, Cam.class);
                intent.putExtra("name", imageData );

Second Activity

protected void onCreate(Bundle savedInstanceState) {

      Bitmap bitmap  = getIntent().getExtras().getParcelable("name");
        ImageView view = (ImageView) findViewById(;



Intent intent = new Intent(this, NewActivity.class);
intent.putExtra("BitmapImage", bitmap);

and retrieve it on the other end:

Intent intent = getIntent();
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");

To start another activity and receive a result back call startActivityForResult() (instead of startActivity()).

In the startActivityForResult pass the image URI and the next context.

I think this should be enough in your scenario.

You can use bundle to pass to another activity.

If the image in your device, you can pass path of the image. Than display from path.

Use this.

Intent intent = new Intent(this, NewActivity.class);
intent.putExtra("path", imagepath);

in your next Activity retrieve as

String image_path = getIntent().getStringExtra("path");
Bitmap bitmap = BitmapFactory.decodeFile(image_path);

Need Your Help

How to check given phone number is international or non-international number in android?

android sms phone-number

My requirement is to find out the message recipient number is an International number or National number.

How do I override a parent class's functions in python?

python inheritance override parent

I have a private method def __pickSide(self): in a parent class that I would like to override in the child class. However, the child class still calls the inherited def __pickSide(self):. How can I