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:
android:orientation=portrait
However, I would suggest you use the following instead:
android:orientation=sensorPortrait
The latter enables the screen to be rotated when the device is flipped upside down (very common with tablet users).

- Method #2: Alternatively you can do it with Java too (programatically). Just add the following code to the OnCreate Method of your Activity Class:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
so that the OnCreate method looks like this:
@Override public void onCreate(Bundle savedInstanceState) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }

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 { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(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.
I’m a physicist specializing in computational material science with a PhD in Physics from Friedrich-Schiller University Jena, Germany. I write efficient codes for simulating light-matter interactions at atomic scales. I like to develop Physics, DFT, and Machine Learning related apps and software from time to time. Can code in most of the popular languages. I like to share my knowledge in Physics and applications using this Blog and a YouTube channel.