2

I have an Activity with a fixed orientation, android:screenOrientation="portrait" in my manifest. I noticed that when pressing Cntl-F11 on the emulator and when a user slides out the keyboard on a device the Activity is destroyed and onCreate is called.

Yet when I use a non-slide out keyboard device the Activity is never destroyed, simply because it is locked to portrait.

Why is there a difference in behavior between devices? Why is an Activity that is locked to portrait, invoking a configuration change? This is really irritating.

Edit: I also experimented with android:configChanges="orientation without any noticeable difference.

user432209
  • 20,007
  • 10
  • 56
  • 75

1 Answers1

1

You can probably prevent this by telling Android you want to handle the configuration changes yourself via the configChanges attribute.

However, doesn't this point out why it is a bad idea to force the app to be in portrait? That is really annoying on phones with a keyboard.

Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82
  • I knew this was going to come up. I originally had this and experimented both ways without success. The keypad is not used in the activity that is forced to portrait. – user432209 Feb 17 '11 at 01:33
  • Ok, I don't know what your app is, but keep in mind that some users navigate using only the arrow keys or trackball. If they have a keyboard, then the keyboard will be open since that is generally where the arrow keys are. – Cheryl Simon Feb 17 '11 at 01:56
  • My guess as to why would be just an implementation detail of how the portrait only is implemented. The phone notices that a rotation has happened, they kill your activity to create the landscape one, but then realize that you want portrait only so create another portrait one. However, thats just a guess. If you want concrete details you probably need to check out the code. – Cheryl Simon Feb 17 '11 at 01:58
  • Well, onCreate is only called once when the config changes with a keyboard even with portrait set. I guess `screenOrientation` just isn't a concrete parameter like I expected. – user432209 Feb 17 '11 at 02:15