MainActivity.java:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getResources().getConfiguration().orientation == Configuration. ORIENTATION_LANDSCAPE)
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
else
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// ...
}
I have also modified the manifest file. However, I'm not sure if these changes are needed, at least android:screenOrientation="unspecified"
is the default screenOrientation value anyway. AndroidManifest.xml:
<activity android:name="MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="unspecified" />