简体   繁体   中英

Locking screen orientation isn't permanent (android:screenOrientation=“portrait”)

Let's say Activity A has portrait set in manifest, and Activity B has unspecified in manifest. It seems that once I used setRequestedOrientation in Activity B, then popping the back stack to Activity A has activity A in landscape. Is this expected behavior? Does that mean that setRequestedOrientation would possibly change behavior of what's specified in AndroidManifest?

If you're manually modifying the orientation using setRequestedOrientation in Activity B, I think you need to manually handle the orientation in Activity A.

You can force an activity to always be one orientation by putting:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Right above your setContentView call.

As answerd before you should use

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

If you want all your activities to be, let's say, Portrait, create an abstract Base Activity and extend it in all your activities

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