I am using ImageView in my example. I set Images as background of imageview in xml. Now I want to change this image background of Imageview at run time.
this is my java code.
changeImage()
{
ImageView imgview=(ImageView)findViewById(R.id.imageView1);
imgview.setImageResource(R.drawable.headerhindi);
}
I am calling this method from onCreate(). First time my method works fine. but when I redirect again to my activity onCreate() using startActivity(myActivityIntent); this method does not works properly means Images does not change according to this method. By default images which is set in xml is shown.
Please help me to find out the solution.
Thank you in advance.
Try moving the call to
changeImage()toonResume().I haven’t tested it, but I have a feeling that what’s happening is that when you call
startActivity()to start the activity again, the activity was not destroyed yet soonCreate()is not called again as per the activity lifecycle: