How Can I Pass Image View Between Activities In Android
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's showin
Solution 1:
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 = newIntent(context, MyActivity.class);
intent.putExtra("imagePath", pathToImage);
startActivity(intent);
And in you receiving activity:
Stringpath= getIntent().getStringExtra("imagePath");
Drawableimage= Drawable.createFromPath(path);
myImageView.setImageDrawable(image);
Solution 2:
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
.
Post a Comment for "How Can I Pass Image View Between Activities In Android"