Block Android orientation as landscape throughout the app?

I checked a lot of questions based on this, but still I can’t figure out how to lock the screen orientation to the landscape through the app.?

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

this does not work for me, it goes back to potrait if another action is used

+7
source share
6 answers

In the manifest, you can set the ScreenOrientation parameter to landscape for all the activities . You have placed for one activity so that other actions open in the portrait, so for fixing set all your activities with orientation as your first action. In XML, it will look something like this:

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

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

 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 

Hello!

+4
source

Hey, check this out. In androidmanifest file inside action add it

 <activity android:screenOrientation="landscape" android:configChanges="keyboard|keyboardHidden|orientation"> 
+3
source

The orientation property must be set for each individual application action.

+1
source

What do you mean by another activity? Configuration - for activity. Let's say if your application has three actions, then you should specify them as landscape.

0
source

To avoid having to do this for each action, you can register the 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) { } }); } } 
0
source

All Articles