Android: Orientation changes erase modifications made to my ImageView?

When a configuration change such as a screen rotation occurs by default your Activity is destroyed and then recreated (onDestroy of the current activity is called, and then the onCreate of a new version of your activity is called).

When a configuration change such as a screen rotation occurs by default your Activity is destroyed and then recreated (onDestroy of the current activity is called, and then the onCreate of a new version of your activity is called). You can either: Stop Android recreating your activity when a configuration change occurs. To do this add android:configChanges="keyboarddden|orientation" to the activity tag in your manifest.

This is not recommend since if you want a different layout etc for different configurations you will have to handle changing the layout yourself. Override onRetainNonConfigurationInstance and return your bitmap from that. In onCreate check if the last non-configuration instance is not null, in which case cast it to a bitmap and then set the image.

For the latter case, use something like the following: @Override public void onCreate(Bundle savedInstanceState) { ... // Check if our activity was just destroyed and re-created final Object retainedFromConfigChange = getLastNonConfigurationInstance(); if (retainedFromConfigChange! = null) { // Activity has just been recreated, get the image we were working on // before the configuration change ImageView iv = (ImageView)ac. FindViewById(R.id.

ImageView1); iv. SetImageBitmap((Bitmap) retainedFromConfigChange); } ... } @Override public Object getLastNonConfigurationInstance() { ImageView iv = (ImageView)ac. FindViewById(R.id.

ImageView1); // We have to return a plain old Bitmap and not a drawable of any sorts // or we will get memory leaks so we need to extract the bitmap from the drawable return ((BitmapDrawable) iv.getDrawable()).getBitmap(); }.

I think you have a solution in this link. stackoverflow.com/questions/456211/activ....

I think you forgot to override the onRetainNonConfigurationInstance() method where you return your bitmap so it will be passed to the new activity. In the new activity you can retrieve the bitmap as you already do by calling getLastNonConfigurationInstance().

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions