Manually Rotate Screen on Android 8.1: A

Feedback

Question:

I am encountering an issue with my application. When I navigate to the settings menu, specifically the Display section, and select the
Auto-rotate
screen, my application runs in landscape mode. However, if I launch another activity from the current one and rotate the device to vertical orientation, then return to the
previous activity
screen by clicking a button, the previous activity loses its configured data when I finish it in the button’s click event. Interestingly, if I disable the device’s Auto-rotate screen option, the previous activity retains its state.

I’m uncertain about the reason behind this behavior.

Please help me to resolve it.

Regards,
Piks


Solution 1:

Override the manual
orientation change
by setting

android_configChanges="orientation|screenSize"

for all activities in the AndroidManifest.xml file.


Solution 2:


Unless you personally handle these events, engaging in activities similar to an
Orientation Change
will result in the recreation of your activity. For more information, refer to the appropriate documentation.

  1. For information on runtime changes, please refer to the Android developer website at http://developer.android.com/guide/topics/resources/runtime-changes.html.
  2. Please refer to the website http://developer.android.com/resources/articles/
    faster-screen
    for information on handling orientation changes.


Solution 3:


To prevent the loss of the previous state, you can take the following steps when rotating the screen.

  1. Stop recreation ( Just define
    android:configChanges
    =”keyboardHidden|orientation|screenSize” ) in android menifest file.

  2. Use following to handler orientation .

     @Override
            public void onConfigurationChanged(Configuration newConfig) {
                super.onConfigurationChanged(newConfig);
    } 
    

To handle the orientation, make sure to account for different layouts in both portrait and landscape modes.

Frequently Asked Questions