[英]Android Activity Rotated
I'm having a problem with an Activity being rotated after I get back from another that has a different screen orientation. 从另一个具有不同屏幕方向的活动返回后,我遇到了一个活动被旋转的问题。
Allow me describe the steps to reproduce this behavior: 请允许我描述重现此行为的步骤:
1.I have an Activity declared in the Manifest like this: 1.我在清单中声明了一个活动,如下所示:
<activity
android:name=".JobActivity"
android:label="@string/title_activity_job"
android:screenOrientation="portrait" />
As you can see, screenOrientation
is set to portrait
如您所见,
screenOrientation
设置为portrait
Inside this Activity I launch another Activity with the following Intent: 在此活动内,我启动另一个具有以下意图的活动:
Intent jobDetailsIntent = new Intent(mActivity, JobDetailActivity.class); startActivity(cameraIntent);
This Activity screen orientation is declared to be landscape
. 此“活动”屏幕方向被声明为
landscape
。
<activity
android:name=".JobDetailActivity"
android:screenOrientation="landscape"
android:theme="@style/ThemeFullscreen" />
JobDetailActivity
when pressing a button, start another Activity waiting for a result. JobDetailActivity
时,启动另一个Activity等待结果。 startActivityForResult(getIntent(activity), requestCode);
This other Activity is declared as portrait
此其他活动被声明为
portrait
<activity
android:name=".QuestionsActivity"
android:screenOrientation="portrait"
android:theme="@style/ThemeFullscreen.Color" />
finish
in order to return to the first Activity ( JobActivity
). finish
以返回第一个活动( JobActivity
)。 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
// Some other stuff
this.finish();
}
} }
At this point, when I get back to JobActivity
I get to see the Activity in landscape
(Remember it was declared as portrait
) for a second and then returns to the original position. 在这一点上,当我回到
JobActivity
我看到了Activity处于landscape
(记住它被声明为portrait
)一秒钟,然后返回到原始位置。
To sum up: 总结一下:
A (portrait) -> B (landscape) -> C (portrait)
After receiving result from C and going back to B 在收到C的结果并返回到B之后
A (portrait) -> B (landscape)
After calling finish
from B 从B呼叫
finish
后
A (landscape)
After a second 一秒钟后
A (portrait)
Any ideas why this may be happening? 任何想法为什么会发生这种情况? Thank you all, your help is much appreciated.
谢谢大家,非常感谢您的帮助。
I don't understand this code: 我不明白这段代码:
Intent jobDetailsIntent = new Intent(mActivity, JobDetailActivity.class);
startActivity(cameraIntent);
There is a difference between the name of intent declare and intent used to start the activity. 意向声明的名称和用于启动活动的意向之间是有区别的。
Maybe the problem is here. 也许问题出在这里。
Thank you. 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.