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.

PhD researcher at Friedrich-Schiller University Jena, Germany. I'm a physicist specializing in theoretical, computational and experimental condensed matter physics. I like to develop Physics related apps and softwares from time to time. Can code in most of the popular languages. Like to share my knowledge in Physics and applications using this Blog and a YouTube channel.
[wpedon id="7041" align="center"]

Leave a Reply

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