How can I get the current screen orientation?

Sheehan Alam picture Sheehan Alam · Sep 8, 2010 · Viewed 149.3k times · Source

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?

Answer

EboMike picture EboMike · Sep 8, 2010
Activity.getResources().getConfiguration().orientation