安卓:活动集前导向的onCreate,但不是在清单(HDMI发行插)是在、但不、导向、清单

2023-09-12 23:44:38 作者:得而不惜就该死

我可以完全管理的方向改变编程方式,由的onCreate 使用 setRequestedOrientation

I can perfectly manage orientation change programatically, by using setRequestedOrientation in onCreate.

一切工作真的很好,直到我插上HDMI连接线。在此之后,该片剂要是在横向模式。所以,当我打开一个活动,就说明首先在山水,然后之后它显示在肖像,(因为我打电话 setRequestedOrientation(variable_with_orientation_desired_by_the_user),其中变量= ActivityInfo.SCREEN_ORIENTATION_PORTRAIT 的onCreate 正如你可以看,我的应用程序不断旋转的用户打开每个活动;

Everything works really fine, until I plug a HDMI cable. After this, the tablet "wants" to be in landscape mode. So when I open an activity, it shows first in "landscape" and then right after it shows in "portrait", (because I'm calling setRequestedOrientation(variable_with_orientation_desired_by_the_user) where variable=ActivityInfo.SCREEN_ORIENTATION_PORTRAIT in onCreate As you can "see", my app keeps rotating on every activity the user opens;

如果我设置orientantion在清单的活动,这个问题部分地消失了,因为在清单中的方向是相同的用户已经回升。如果它们是不同的,相同的行为再次开始。

If I set the orientantion for activity in the manifest, this problem is partially gone, since the orientation in manifest is the same that the user has picked up. If they are different, the same behavior starts again.

我想这一点,但没有成功:

I tried this, but with no success:

@Override
public void onCreate(final Bundle saved)
{
    setRequestedOrientation(ScreenOrientation);
    super.onCreate(icicle);
}

那么,有没有办法告诉到Android什么orientantion它必须创造我的活动,才不会产生呢? (但它不能在清单)

So, is there any way to tell to android what orientantion it must create my activity, before it does create it? (But it cannot be in manifest)

推荐答案

我通过设置screenOrientation解决它背后的清单文件:

I solved it by setting screenOrientation to "behind" in manifest file:

        android:screenOrientation="behind"