0
votes

I'm currently developing an app, in which phones have forced portrait mode, while tablets support portrait mode as well as landscape mode. Some pages the layouts have respective landscape versions in the layout-land folder.

The problem

While using the app on a phone (so portrait only) and when autorotate on the phone is enabled, the landscape layout file gets loaded while the app is displayed as portrait mode.

When does this occur

To recreate this behaviour I open an activity and rotate the device. Then when I navigate to another activity, or close and open the application, the landscape layout gets loaded.

Method of forcing portrait mode

To force portrait mode on phones, I call

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

in my BaseActivity onCreate method.

Other details

targetSdkVersion: 26 using support library 26.0.0

Thank you for helping!

Edit 1:

Unfortunately using (a combination of) the following settings in the manifest file gives the same behaviour.

  • android:screenOrientation="sensorPortrait"
  • android:screenOrientation="portrait"
  • android:configChanges="orientation"

Edit 2:

I've now tested on multiple devices (emulator, One plus, Motorola, Samsung and some more) and this oddity only happens on a Samsung A5 (api 23) for me.

4

4 Answers

0
votes

Is other Activities are also have that code?
I meant, other Activity that doesn't extends BaseActivity?

I would prefer to set in AndroidManifest.xml file in each activity tag like >> android:screenOrientation="portrait"

0
votes

add this line android:screenOrientation="portrait" in your project manifest file inside activity. Hope it work well.

0
votes

Try this

<activity
            android:name=".Activity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/title_activity_test_edit"
            android:screenOrientation="sensorPortrait"
            android:theme="@style/Theme.DesignDemo"
            android:windowSoftInputMode="stateAlwaysHidden" />

Portrait orientation, but can be either normal or reverse portrait based on the device sensor.

Refer this link for more details :

https://developer.android.com/guide/topics/manifest/activity-element.html

0
votes

As you mentioned,

phones have forced portrait mode, while tablets support portrait mode as well as landscape mode

Set screen orientation in manifest will not work. Use layout-land-sw600dp, layout-land-sw720dp folders for landscape view for tablets. Also please take a look at this SO thread