Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is application orientation (landscape or portrait) locked?

I have tried to freeze orientation using:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Although the display stays in portrait orientation, the activity is still recreated. Any ideas how to solve this?

How can the orientation of the application be locked such that the activity is not recreated on orientation change?

like image 336
alex2k8 Avatar asked Apr 18 '10 18:04

alex2k8


People also ask

How do I lock my app orientation?

On the main screen of Rotation Manager, select an orientation by tapping on either the vertical or horizontal icons next to a specific app to lock it into either landscape or portrait mode. Highlighting both icons will allow that particular app to auto-rotate.

How do I unlock portrait orientation lock?

Simply turn your Apple® iPhone® to change the view. Access the Contol Center by swiping downward from the upper-right corner of the Home or Lock screen. For the iPhone with Touch ID, access the Control Center by touching the bottom of any screen then dragging upward. to lock or unlock screen portrait orientation.

How do I change apps from portrait to landscape?

Setting the app upWhen on the main screen, under the orientation section, you will see a number of options like 'Auto-rotate OFF', 'Auto-rotate ON', 'Forced Portrait' and 'Forced Landscape'. As the names suggest, you can use these buttons as one-tap shortcuts to toggle the orientation of your device.


1 Answers

First, don't use setRequestedOrientation() if you can avoid it. Use the android:screenOrientation attribute in your <activity> manifest element instead.

Second, you will also need android:configChanges="keyboardHidden|orientation" in your <activity> manifest element to prevent the destroy/recreate cycle.

like image 145
CommonsWare Avatar answered Nov 15 '22 22:11

CommonsWare