How can i pass image view between activities in android

前端 未结 2 839
情歌与酒
情歌与酒 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);
    
    0 讨论(0)
  • 2020-12-06 22:08

    You absolutely do not want to pass an image view from one activity to another. Views keep a reference to their ViewContainer and parent Activity. This prevents the Garbage Collector from clearing up memory when the Activity that owns the View gets hidden or closes. Instead you should pass the information required to replicate the ImageView from activity to another using Intents.

    0 讨论(0)
提交回复
热议问题