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?


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.