-3

I am new in android.i want to pass image in one activity to another activity.I tried many time.but my app gonna crash.plz edit my code with necessary changes.

Sender activity:

camera=(ImageButton)findViewById(R.id.camera);
            gallery=(ImageButton)findViewById(R.id.gallery);
      camera.setOnClickListener(new View.OnClickListener() {

          @Override
          public void onClick(View view) {
              Intent i =new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
              startActivityForResult(i, 50);
          }
      });

    gallery.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent pickPhoto = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(pickPhoto , 40);
        }
    });
}

Receiver activity:

package com.androidlink.navigation_bottom;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;


import android.os.Bundle;
import android.widget.ImageView;
public class Image_set_Activity extends AppCompatActivity 
{


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_set_);
    ImageView IV = (ImageView) findViewById(R.id.simpleImageView);

  }
}
Kerberos
  • 4,036
  • 3
  • 36
  • 55
  • Possible duplicate of [Android - how to set an alarm to a specific date](https://stackoverflow.com/questions/4700285/android-how-to-set-an-alarm-to-a-specific-date) – K M Rejowan Ahmmed Oct 21 '18 at 20:04
  • You Can use this thread of Stackoverflow [https://stackoverflow.com/a/39243081/9932194](https://stackoverflow.com/a/39243081/9932194) – K M Rejowan Ahmmed Oct 21 '18 at 20:06

2 Answers2

0

Try to override onActivityResult(). For further reading - https://developer.android.com/training/basics/intents/result

Ofek Regev
  • 467
  • 4
  • 18
-1

Try this code For sending the image

ImageView imageview = (ImageView) findViewById(R.id.Tab);
BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
Bitmap bitmap = drawable.getBitmap();
final byte[] arr = bitmap.getNinePatchChunk();

imageView.setOnClickListener(View v)
{
Intent intent = new Intent (MainActivity.this,bbb.class);
Intent.putExtra(“image”,arr);
startActivity(intent);
}

For getting the image

Intent I = getIntent();
byte[] arr1 = i.getByteArrayExtra(“image”);
Bitmap map = BitmapFactory.decodeByteArray(arr,0,arr.length);
imageView.setImageBitmap(map);
Vishal Sharma
  • 1,051
  • 2
  • 8
  • 15