Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity rotating itself and back to normal in android 8.1

My App is running fine for all the android version but I have noticed that in Android 8.1.0 (Oreo) when I go the screen from portrait activity to landscape activity and when I press back button it shows the abnormal behavior.

Screen auto rotate from landscape and returns it to normal. It looks like Activity is restarting itself.

Below are the activities which is define in the manifest file.

<activity
    android:name=".Home.TrainingsActivity"
    android:configChanges="keyboardHidden|orientation|screenSize|layoutDirection|locale"
    android:screenOrientation="portrait" />

<activity
    android:name=".Home.ProgrammeActivity"
    android:configChanges="keyboardHidden|orientation|screenSize|layoutDirection|locale"
    android:screenOrientation="landscape" />
like image 339
Ahmad Arslan Avatar asked Mar 19 '18 10:03

Ahmad Arslan


People also ask

Why is my phone automatically rotating?

When this accessibility setting is on, the screen automatically rotates when you move your device between portrait and landscape position. If you're using TalkBack, you might want to turn off auto-rotate, since rotating the screen can interrupt spoken feedback.

What happens when Android screen rotates?

When you rotate your device and the screen changes orientation, Android usually destroys your application's existing Activities and Fragments and recreates them. Android does this so that your application can reload resources based on the new configuration.


1 Answers

We also faced the same issue with Oreo. We actually can't triggered why its happening with the specific OS version. But we do had a solution to cater this problem. You can add force Orientation to portrait when finishing your landscape activity. add this this with onBackPressed() methond in ProgrammeActivity.

 @Override
public void onBackPressed() {
    super.onBackPressed();
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

this should solve this abnormal behavior :)

like image 163
Abdul Wahab Avatar answered Nov 16 '22 04:11

Abdul Wahab