alex2k8 alex2k8 - 1 year ago 75
Android Question

How is application orientation (landscape or portrait) locked?

I have tried to freeze orientation using:


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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download