How to disable landscape mode/orientation for an Activity? (Android Studio) [Solution]

It is very easy to disable the landscape mode for your activity.
You can do it in two ways:

  • Method #1: Just open your AndroidManifest.xml file and add the following code to the activity or activities for which you want to disable the landscape orientation:

However, I would suggest you use the following instead:


The latter enables the screen to be rotated when the device is flipped upside down (very common with tablet users).

Disabling Landscape Mode using XML
Disabling Landscape Mode using XML
    • Method #2: Alternatively you can do it with Java too (programatically). Just add the following code to the OnCreate Method of your Activity Class:

so that the OnCreate method looks like this:

public void onCreate(Bundle savedInstanceState) {
Disabling Landscape Mode using JAVA(Prrogramatically)
Disabling Landscape Mode using JAVA(Prrogramatically)

To disable landscape orientation on all the Activities just follow any of the methods above for all the activities.
However, there is a rather simple way to disable landscape Orientation for the whole Application(for all the Activities).
I found it on StackOverflow.

All you need to do is make an Abstract Activity that all your Activities extend.

public abstract class AbstractActivity extends Activity {
    protected void onCreate(Bundle savedInstanceState) {
        setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Well that’s it!!
I hope this tutorial helped you.
If you have any question or doubt just leave it in the comments section down below.

Hey! I am a Physics Major at the University of Delhi.
I dream of being a Theoretical Physicist one day. I love playing Guitar in my free time. I can speak English, Hindi and a little French. I am also a Web Development Enthusiast and a hardcore Gamer.

Leave a Reply

Your email address will not be published. Required fields are marked *