Manually Rotate Screen on Android 8.1: A



I am encountering an issue with my application. When I navigate to the settings menu, specifically the Display section, and select the
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.


Solution 1:

Override the manual
orientation change
by setting


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
  2. Please refer to the website
    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
    =”keyboardHidden|orientation|screenSize” ) in android menifest file.

  2. Use following to handler orientation .

            public void onConfigurationChanged(Configuration newConfig) {

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

Frequently Asked Questions