I am trying to start a new activity when an Android device is rotated, but I don;t even seem to be detecting the rotation in the emulator.
I've read the thread at Android: listen for Orientation change? and that all seems to amke sense, but its just not working.
In my manifest I have:
<activity android:name=".MainActivity" android:configChanges="orientation|screenSize" android:screenOrientation="portrait" android:windowSoftInputMode="stateHidden"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> and in my mainActivity.java I have:
@Override public void onConfigurationChanged (Configuration newConfig) { super.onConfigurationChanged(newConfig); int orientation=newConfig.orientation; switch(orientation) { case Configuration.ORIENTATION_LANDSCAPE: showMessage("landscape"); break; case Configuration.ORIENTATION_PORTRAIT: showMessage("portrait"); break; } } This obviously won't start the new Activity, but I am trying to get the orientation detection working first (showMessage just calls a Toast and is working elsewhere in my code, so that's not why I am not seeing anything).
When I run this in the emulator and use the rotate buttons, the emulator rotates as expected but I never see the Toast...
Where am I going wrong? (I am importing android.content.res.Configuration as required for the Configuration constants).