1

i am using an imageView to display an image. later i am setting a different image to the view using imageView.setImage(bitmap).now if i change the orientation of the screen from portrait to landscape, the imageview displays the old image instead of the new image i have set. can someone pls tell me why this happens and how to overcome this.

Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
chethan
  • 63
  • 3
  • 12

4 Answers4

2

Normal case when you change you orientation the activity will recreate(call onCreate()).
If you have only one xml for both orientation, you can block this by
1. Set the activity as android:configChanges="orientation" in manifest file

<activity android:name=".Youractivityname" 
      android:configChanges="orientation"/>

2. Then override this in our activity class

public class Youractivityname extends Activity {

     public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            // all your codes 
      }

    @Override
        public void onConfigurationChanged(Configuration newConfig) {
          super.onConfigurationChanged(newConfig);

        }
}

Hope now it is clear for you

Labeeb Panampullan
  • 34,521
  • 28
  • 94
  • 112
  • sorry, but i dont see how this helps.what would i need to do in this method. could you pls give me some more details – chethan Jan 12 '11 at 10:52
  • Rather than blindly ignoring all configuration changes, you should handle them. See, for example, this article: http://developer.android.com/intl/fr/resources/articles/faster-screen-orientation-change.html – Christopher Orr Jan 12 '11 at 11:31
  • Also, there are other configChanges aside from "orientation" that will cause this to happen, e.g. the user opening the hardware keyboard or the locale changing. – Christopher Orr Jan 12 '11 at 11:32
  • See also: http://developer.android.com/guide/topics/resources/runtime-changes.html – Christopher Orr Jan 12 '11 at 11:49
0

Using android:configChanges="orientation" in the manifest is a bad practice. This is the recommended way to handle the orientation change.

Community
  • 1
  • 1
backslashN
  • 2,795
  • 3
  • 15
  • 25
0

By default on orientation change the activity is destroyed and recreated, so if you set the first bitmap on create, and then change to the second bitmap elsewhere, when the orientation changes the first image is set in the onCreate but if the code that changes image isn't called again then the image doesn't change.

maid450
  • 7,478
  • 3
  • 37
  • 32
0

I had a problem while changing the screen portrait to landscape the image is hide .I used the line in AndroidManifest.xml in activity below my problem was solved

 android:configChanges="orientation|screenSize"
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
S HemaNandhini
  • 333
  • 3
  • 5