[ACCEPTED]-Lock the android orientation as landscape throughout the App?-android

Accepted answer
Score: 15

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

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

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

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Greetings!

0

Score: 4

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

<activity
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation">
Score: 1

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

Score: 1

To avoid having to do this for every activity 3 you can register an activity lifecycle callback 2 in your custom application class (if you 1 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) {

            }
        });
    }
}
Score: 0

What do you mean by another activity? The 3 configuration is per activity. Say if your 2 application has three activity then you 1 must specify each one as landscape.

More Related questions