20

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

1
  • I see the same in 2.3.3 emulator now... 1.6 and 2.1 work fine though... makes testing difficult :)
    – Jay
    Dec 1, 2011 at 3:30

7 Answers 7

9

FWIW, it's officially reported as bug here.

1
  • 3
    The workaround is to hit the home button when you are in portrait mode, that will reset the gravity sensor
    – StuTheDog
    Aug 21, 2011 at 19:28
4

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.

3

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.

1
  • 1
    When you change the orientation, the activity is re-created and its onCreate() method is called again which re-creates the whole activity. So its not a bug..
    – YuDroid
    Jun 27, 2012 at 10:12
1

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.

0

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.

0

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
    super.onConfigurationChanged(newConfig);
    startActivity(getIntent());
    finish();

}

and reload the current activity. It will help you.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.