活动自动旋转并在Android 8.1中恢复正常 [英] Activity rotating itself and back to normal in android 8.1

查看:231
本文介绍了活动自动旋转并在Android 8.1中恢复正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在所有android版本上都运行良好,但是我注意到在Android 8.1.0(Oreo)中,当我从纵向活动转到横向活动时,当我按返回按钮时,它显示异常行为。

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.

屏幕自动从横向旋转并返回到正常状态。
似乎Activity正在重新启动。

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


推荐答案

我们也遇到了与Oreo相同的问题。实际上,我们无法触发为何特定操作系统版本会发生这种情况。但是我们确实有解决此问题的解决方案。
完成风景活动时,可以向肖像添加力方向。
通过ProgrammeActivity中的onBackPressed()方法添加此内容。

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

这篇关于活动自动旋转并在Android 8.1中恢复正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆