Force android app to run in Landscape mode programatically

If you have a requirement to design an Android Application that runs only in Landscape Mode (say you are designing a game) then you need to set orientation as LANDSCAPE for each activity class that you have.

How to do it ?

In your activity class add setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) just before setContentView(R.layout.activity_main) in onCreate method.

package com.code2care.examples;

import android.os.Bundle;

public class LayoutExampleActivity extends ActionBarActivity {

    protected void onCreate(Bundle savedInstanceState) {

       //This will make your app run only in Landscape mode!


Note : You have to add setRequestedOrientation() to each Activity class to force it work only in landscape.

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap