How can i pass image view between activities in android

前端 未结 2 860
情歌与酒
情歌与酒 2020-12-06 21:12

I want to send the ImageView form one activity to another activity. When i am trying to pass the image view from Class A to Class B using bundle concept then in class B it\'

2条回答
  •  醉梦人生
    2020-12-06 21:57

    You shouldn't be passing views between activities. You should use extras to pass the location of the image in the intent and load it again in your new activity.

    Ex:

        Intent intent = new Intent(context, MyActivity.class);
        intent.putExtra("imagePath", pathToImage);
        startActivity(intent);
    

    And in you receiving activity:

        String path = getIntent().getStringExtra("imagePath");
        Drawable image = Drawable.createFromPath(path);
        myImageView.setImageDrawable(image);
    

提交回复
热议问题