Reputation: 3083
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
Upvotes: 11
Views: 34744
Reputation: 356
You can also use the following in the onCreate()
method:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Greetings!
Upvotes: 7
Reputation: 4586
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) {
}
});
}
}
Upvotes: 2
Reputation: 6128
Hey check this out In the androidmanifest file inside activity add it
<activity
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation">
Upvotes: 4
Reputation: 181
The orientation property has to be set to every individual activity of the application.
Upvotes: 1
Reputation: 6023
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>
Upvotes: 15
Reputation: 5969
What do you mean by another activity? The configuration is per activity. Say if your application has three activity then you must specify each one as landscape.
Upvotes: 0