I'm new to android, I encountered this problem while learning the basics.
I've searched for my problem in google and here but can't find similiar one.
My problem is I can't detect when the screen orientation changed to landscape.
Here's the code I got from here
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
System.out.println("orientation landscape");
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
System.out.println("orientation potrait");
} else{
Toast.makeText(this, "undefined", Toast.LENGTH_SHORT).show();
System.out.println("orientation undefined");
}
}
<activity android:name=".Hello2011Activity"
android:label="@string/app_name"
android:theme="@style/testem"
android:configChanges="orientation"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Here's the log
07-27 16:19:11.935: INFO/ActivityManager(52): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=2 layout=18}
07-27 16:19:12.065: INFO/ActivityManager(52): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=18}
07-27 16:19:12.305: INFO/System.out(1241): orientation potrait
07-27 16:19:15.485: INFO/ActivityManager(52): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/1 nav=3/1 orien=2 layout=18}
07-27 16:27:11.465: INFO/ActivityManager(52): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=2 layout=18}
07-27 16:27:11.665: INFO/ActivityManager(52): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=18}
07-27 16:27:11.885: INFO/System.out(1241): orientation potrait
07-27 16:27:14.035: INFO/ActivityManager(52): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/1 nav=3/1 orien=2 layout=18}
07-27 16:27:20.401: INFO/ActivityManager(52): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=2 layout=18}
07-27 16:27:20.675: INFO/ActivityManager(52): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=18}
07-27 16:27:20.865: INFO/System.out(1241): orientation potrait
As you can see there's only notification for when I change the orientation changed from landscape to potrait and not vice versa.
I've tried avd 2.1update1 with api level 7 and avd 2.2 with api level 8. OS is windows xp sp 3 with eclipse 3.6.2.
Is this a bug or there's something wrong with the code?