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
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.
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.
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>
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) {
}
});
}
}
You can also use the following in the onCreate()
method:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Greetings!
Hey check this out In the androidmanifest file inside activity add it
<activity
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation">
The orientation property has to be set to every individual activity of the application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With