Question

I have an activity used to display a video (VideoView). By default the user can change screen orientation to see the video. I avoid destroying/recreating the activity upon orientation changes because of latency issue. The rotation is painless without any sound break.

android:configChanges="keyboardHidden|orientation|screenSize"

What I want to do now is add a button that will force the activity to remain on current orientation.

The problem is that because the activity isn't recreated after the rotation, I don't know which method to override to avoid the rotation to happen. Overriding onConfigurationChanged is useless because the rotation already happened.

Was it helpful?

Solution

Use setRequestedOrientation().

E.g. to lock the orientation to portrait, call:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

In your activity.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top