android force lauch activity in landscape mode
Try overriding the onConfigurationChanged
method.
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
how to set landscape orientation in particular activity?
To lock your Activity during runtime, you can use
// lock orientation to landscape
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
All you need now is to determine the current orientation, and pass it to keep it locked that way.
First, add these imports:
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
Then you can add this to your Activitys onCreate():
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// lock the current device orientation
int currentOrientation = this.getResources().getConfiguration().orientation;
if (currentOrientation == Configuration.ORIENTATION_PORTRAIT){
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
else{
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
// ... rest of your code
}
See ActivityInfo documentation for the other orientation configurations.
Android: Force landscape orientation but allow rotation
You just need to set the android:screenOrientation
attribute in your AndroidManifest.xml to sensorLandscape
Related Topics
Youtube Video Not Playing in Webview - Android
How to Get Higher Precision of "Cpu%" Than That from Top Command
Multi Flavor App Based on Multi Flavor Library in Android Gradle
Android Gradle Could Not Reserve Enough Space for Object Heap
How to Pass Integer from One Activity to Another
Phonegap - Add a Splash Screen for Android App
How to Convert Dp, Px, Sp Among Each Other, Especially Dp and Sp
Initializing Games Client in Android
Connectivitymanager Getnetworkinfo(Int) Deprecated
How to Tell If Android App Is Running in the Foreground
How to Use Web Camera in Android Emulator to Capture a Live Image
"No Such File or Directory" Trying to Execute Linux Binary on Android Device
Detect from Browser If a Specific Application Is Installed in Android
Open an Image Using Uri in Android's Default Gallery Image Viewer
Manifest Merger Fails for Appcomponentfactory
The APK File Does Not Exist on Disk
Can't Create Handler Inside Thread Which Has Not Called Looper.Prepare()