In the application one main activity and several fragments. I need one of the fragments (MyLandscapeFragment) to always be in landscape orientation, and the rest to choose the sensor of the device.
The manifest states:
<activity android:name=".MainActivity_" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation|screenSize" android:launchMode="singleTask"> In the main activity implemented:
@Override public void onConfigurationChanged(Configuration newConfig){ super.onConfigurationChanged(newConfig); // *** if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { startMyLandscapeFragment(); } // *** } To start the MyLandscapeFragment, before that I call
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) which in turn is transmitted to onConfigurationChanged , from where the necessary fragment is launched. If after this you exit the application by pressing the back button once, then restart, then calling setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) again will lead to nothing, onConfigurationChanged will not be called, the orientation will not change.