How do I disable portrait/landscape mode after the app is started? Say, if I start the app in landscape mode, it stays in landscape mode. If I start it in portrait mode, it stays in portrait mode?
Thank you
How do I disable portrait/landscape mode after the app is started? Say, if I start the app in landscape mode, it stays in landscape mode. If I start it in portrait mode, it stays in portrait mode?
Thank you
Please refer Below Link
orientation lock in android programmatically
You can maintain your preference to stay in particular landscape/protrait mode
You might create two acitivties which is either started in landscape or portrait mode. To disable the opposite, do as already said.
android:screenOrientation="portrait"
Simple Once your app is started get the orientation of the device.Then set that orientation to all your activities.
In your first activity's onCreate method get the current orientation of the device like this
int orientation = getResources().getConfiguration().orientation;
setRequestedOrientation(orientation);
This will set the orientation for the current activity only.But if you want to set the whole app to this mode then try this Create a helper class like this
Class ActivityHelper{
public static void setOrientation(Activity activity,int orientation){
activity.setRequestedOrientation(orientation);
}
}
in your Everyactivity after setContentView call
ActivityHelper.setOrientation(this,orientation);//Keep orientation as a static variable