Orientation: portrait vs. landscape


The important point is that the Activity’s onDestroy and onCreate methods are called whenever the orientation changes.

Source code in Orientation.zip

  1. MainActivity.java
  2. activity_main.xml: added android:id attribute to TextView.
  3. AndroidManifest.xml: added android:screenOrientation="fullSensor" attribute to <activity> element.

Android Emulator

The keystrokes that change the orientation of the emulator are different on Mac and PC.

android:screenOrientation property in AndroidManifest.xml

Eclipse gives us a default AndroidManifest.xml file whose activity element does not have the android:screenOrientation property. The default value of this property is "unspecified", which means the device can do whatever it wants. With the default value, the emulator was able to go to “portrait 0” and “landscape 90”. My Motorola Sprint MB612 (Android 2.3.5, SDK 10) went to was also able to go to “landscape 270”. Adding the android:screenOrientation="fullSensor" attribute had no effect on the emulator; my phone gained “portrait 180”.

iOS, by the way, has six orientations, including face up and face down.