-1

My main activity contains the imageview and editactivity has a button for changing the image in imageview . I used the Intent to startActivityForResult and onActivityResult code is shown below

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {

        Uri uri = data.getData();


        try {
            bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
            View mainactivity;


            ImageView imageprofile;
            mainactivity= LayoutInflater.from(this).inflate(R.layout.activity_main,null);
            imageprofile = (ImageView)mainactivity.findViewById(R.id.ProfileImage);


            imageprofile.setImageBitmap(bitmap);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

The image choosen is not set , please help

Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
Math_Zombie
  • 135
  • 5

1 Answers1

0

You should not pass Bitmap to another activity.

Passing the entire bitmap requires a lot of memory

Pass the URI to another activity and load if needed. Hope it helps!

Liar
  • 1,235
  • 1
  • 9
  • 19