简体   繁体   中英

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:

<activity
android:name=".JobActivity"
android:label="@string/title_activity_job"
android:screenOrientation="portrait" />

As you can see, screenOrientation is set to portrait

  1. 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 .

<activity
android:name=".JobDetailActivity"
android:screenOrientation="landscape"
android:theme="@style/ThemeFullscreen" />
  1. The Activity JobDetailActivity when pressing a button, start another Activity waiting for a result.

startActivityForResult(getIntent(activity), requestCode);

This other Activity is declared as portrait

<activity
android:name=".QuestionsActivity"
android:screenOrientation="portrait"
android:theme="@style/ThemeFullscreen.Color" />
  1. When I get the result from this other Activity, and after doing a couple of things, I call finish in order to return to the first Activity ( 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.

To sum up:

A (portrait) -> B (landscape) -> C (portrait)

After receiving result from C and going back to B

A (portrait) -> B (landscape)

After calling finish from B

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM