Search code examples
androidorientationscreen-orientation

Changing the Orientation Smoothly for SDK from App


I know the question related to orientation has been asked multiple times, but I am facing some weird issue. I am working on one SDK that has some Activity which can be opened from the App, The SDK asks for the orientation values from the App and I am updating the orientation in onCreate() of the Activity by setting:

requestedOrientation = orientation

It works perfectly when I am holding the device in the same orientation as the orientation is set by App. But If I am holding the device in portrait mode and setting the requestedOrientation to LANDSCAPE then my screen flickers, 1st it shows the portrait screen and then goes to landscape. In manifest I have set the configChanges to android:configChanges="keyboard|keyboardHidden|screenSize" I have separate layouts for both the orientations. Let me know, if anything else is also required.


Solution

  • We have implemented a solution at our end as below, Now the clients are declaring the same Activity in their manifest file and replacing the orientation as per their requirements.

    SDK Manifest:

    <activity
            android:name=".ActivityName"
            android:configChanges="keyboard|keyboardHidden|screenSize"
            android:exported="false"
            android:label="@string/title_activity_login"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden" />
    

    Client Manifest:

    <activity
            android:name="sdkPackage.ActivityName"
            tools:replace="android:screenOrientation"
            android:screenOrientation="sensorLandscape"/>
    

    sdkPackage is the complete package of SDK, basically the client is now overriding the android:screenOrientation and setting it to whatever orientation they want.