Inverted rotation does not cause a configuration change

When I turn my Android phone up, my activity does not rotate to show the layout upside down, but remains in landscape mode. I tried this with a very simple HelloWorld application. I added android:configChanges="orientation"to the manifest and turned it over onConfigurationChange()to Activity to set breakpoints there. Turning the device upside down causes one configuration change to go from portrait (up) to landscape, but without a second change from landscape to portrait (upside down). Is this a problem with Android or is there something I need to do?

manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="hello.world"
    android:versionCode="1"
    android:versionName="1.0" >
   <uses-sdk android:minSdkVersion="10" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:configChanges="orientation"
            android:name=".HelloWorldActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

Activity:

public class HelloWorldActivity
  extends Activity
{
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
  }

  public void onConfigurationChanged(Configuration newConfig)
  {
    super.onConfigurationChanged(newConfig);
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
    {
      Log.e("MDO", "orientation change: landscape");
    }
    else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
    {
      Log.e("MDO", "orientation change: portrait");
    }
  }
}
+5
source share
3 answers

, Android. , ( 2.2, ). , . , , . tutorial , , SensorManager docs.

EDIT: , android:screenOrientation="fullSensor" , , - Android 2.3 ( API 9).

+7

screenSize configChanges :

android:configChanges="orientation|screenSize"

http://developer.android.com/guide/topics/resources/runtime-changes.html:

Android 3.2 ( API 13), " " , . , API 13 ( minSdkVersion targetSdkVersion), "screenSize" "". , android: configChanges = "orientation | screenSize". , API 12 , ( Android 3.2 ).

+3

The setup android:screenOrientation="fullSensor"does what I'm trying to do.

+3
source

All Articles