How can I get the current screen orientation?
I just want to set some flags when my orientation is in landscape so that when the activity is recreated in onCreate() i can toggle between what to load in portrait vs. landscape. I already have a layout-land xml that is handling my layout.
public void onConfigurationChanged(Configuration _newConfig) {
if (_newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
this.loadURLData = false;
}
if (_newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
this.loadURLData = true;
}
super.onConfigurationChanged(_newConfig);
}
Over-riding onConfigurationChanged will prevent my layout-land xml from loading in landscape orientation.
I just want to get the current orientation of my device in onCreate(). How can I get this?
Solution 1:
Activity.getResources().getConfiguration().orientation
Solution 2:
int orientation = this.getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
// code for portrait mode
} else {
// code for landscape mode
}
When the superclass of this
is Context