Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lock the android orientation as landscape throughout the App?

Tags:

android

I have checked many question based on this but still I am not able to get it how to lock the screen orientation to landscape through out the app. ?

<activity android:screenOrientation="landscape"
      android:name=".BasicLayoutCheckActivity"
        />

this is not working for me it comes back to potrait if another activity is used

like image 561
user1169079 Avatar asked Feb 14 '12 11:02

user1169079


People also ask

How do I keep my Android in landscape mode?

2 Tap Home screen settings. 3 Tap the Portrait mode only switch to deactivate it. 4 Rotate the device until it is horizontal to view the screen in landscape mode.

How do I force all apps in landscape mode?

Setting the app up When on the main screen, under the orientation section, you will see a number of options like 'Auto-rotate OFF', 'Auto-rotate ON', 'Forced Portrait' and 'Forced Landscape'. As the names suggest, you can use these buttons as one-tap shortcuts to toggle the orientation of your device.


5 Answers

In the Manifest, you can set the screenOrientation to landscape for all the activities . You have placed for one activity so other activities are opening in portrait, So for fixing set all your activities with orientation as your first activity. It would look something like this in the XML:

<activity android:name=".BasicLayoutCheckActivity" android:screenOrientation="landscape"></activity>
like image 122
Udaykiran Avatar answered Oct 19 '22 20:10

Udaykiran


To avoid having to do this for every activity you can register an activity lifecycle callback in your custom application class (if you have one).

Something like...

public class MyApplication extends Application {

   @Override
    public void onCreate() {
        super.onCreate();

        //Lock orientation in landscape for all activities, yaay!
        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
                 activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);                  
            }

            @Override
            public void onActivityStarted(Activity activity) {

            }

            @Override
            public void onActivityResumed(Activity activity) {

            }

            @Override
            public void onActivityPaused(Activity activity) {

            }

            @Override
            public void onActivityStopped(Activity activity) {

            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

            }

            @Override
            public void onActivityDestroyed(Activity activity) {

            }
        });
    }
}
like image 34
Jraco11 Avatar answered Oct 19 '22 21:10

Jraco11


You can also use the following in the onCreate() method:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Greetings!

like image 40
RKuehn Avatar answered Oct 19 '22 21:10

RKuehn


Hey check this out In the androidmanifest file inside activity add it

<activity
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation">
like image 38
Goofy Avatar answered Oct 19 '22 22:10

Goofy


The orientation property has to be set to every individual activity of the application.

like image 42
Dinesh Avatar answered Oct 19 '22 21:10

Dinesh