Activity rotating itself and back to normal in android 8.1

放肆的年华 提交于 2020-01-12 07:20:12

问题


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" />

回答1:


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 :)



来源:https://stackoverflow.com/questions/49360236/activity-rotating-itself-and-back-to-normal-in-android-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!