android – Screen orientation landscape back to portrait not working-ThrowExceptions

Exception or error:

I’ve racked my brain for hours over this issue. I have created a main.xml and designed one for the res/layout-land (landscape) format and another one for portrait in res/layout.

When I rotate the emulator (ctrl-F11), my app rotates properly to landscape using the correct main.xml, but a subsequent rotation back to portrait just keeps the landscape mail.xml.

This was done in a 2.0 AVD..

Out of despiration I downloaded the new Sample Code for Multiple Resolutions and had to create a new 2.1 AVD, to my surprise rotation with this app works correctly as expected. So I then decided to try my app on the 2.1 AVD and it works perfectly.

So, is this a Bug in a 2.0 AVD or is there something special I need to be doing for < 2.1 SDK versions?

This is driving me crazy because no where did anyone mention this issue.

Thanks in advance

How to solve:

FWIW, it’s officially reported as bug here.


Installed a fresh Android development environment, and created a new 2.3.3 AVD. (Both arm and x86). Both have the same problem, even with the system apps. So it’s not a bug in your code, cause the system apps have the same problem.

Pressing ‘home’ and restarting your app works to get it back to portrait though.


Unless you specify

<activity android:name="MainActivity" android:configChanges="orientation">

In your manifest, I think your app should automatically select the correct layout.xml. So, seems like a bug in the emulator to me. Anyway, I found that the emulator is buggy in other ways. Ex. it runs the code twice when you change the orientation back.


I am using Eclipse for Java Helios, and Android 2.2 and I experienced this same problem on my laptop. I found out what the problem was for me at least. Sometimes I work on my laptop in an area that doesn’t have wifi so I am not connected to the internet and this seems to cause this problem. I have tested it by going to a wifi hotspot and, sure enough, the switching between portrait and landscape and back again works fine. Maybe the emulator just has to have a connection to do that or it is a bug in the emulator.


Yes, the emulator is a bit buggy when it comes to orientation changes. I haven’t experienced this specific problem, but it does sometimes do strange things. However this definitely isn’t an issue with < 2.1 SDKs, on a physical phone at least, because I’m still stuck with v1.5 on my Hero and it properly handles orientation changes by picking the right layout folder to get the xml files from.


I was also faced same problem. I solved it. I don’t think this is an emulator bug. I think in some real phones also it will behave like this. The main reason is the activity is not refreshing. You can do one thing – override the

public void onConfigurationChanged(Configuration newConfig) {
    // TODO Auto-generated method stub


and reload the current activity. It will help you.


I’ve only done 2.1 development, but another thought I just had would be to try CTRL-F12 (Switch to NEXT layout orientation) instead of CTRL-F11 (Switch to PREVIOUS layout orientation () and see if anything changes. This is from Controlling the Emulator.

Also, there are a number of lifecycle methods you could override to monitor what is happening behind the scenes. That might let you know if there’s a bug in the emulator.

Leave a Reply

Your email address will not be published. Required fields are marked *