Search code examples
javaandroidscreenandroid-manifestscreen-rotation

Disable Screen Orientation Dynamically In Android(Java)


I want to lock my application to portrait mode for all the activities. I know this can be done by setting android:screenOrientation="landscape" in activity tag in manifest. but I have lots of activities, so I was wondering is there any way to do it on application level either by some xml tag in manifest or in code anyhow, so I wont have to define it in all the activity tags.


Solution

  • setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    

    Or

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    

    Use this method in the BaseActivity. And extend this activity for every other activity in your application.