Prash's Blog

How to set Android App orientation on startup April 21, 2012

Filed under: Android — prazjain @ 5:50 pm

While coding one of the android app, i overwrote OnConfigurationChanged method to change the app orientation when user changes orientation. But there was a problem if the user starts the app in landscape mode, my app would by default still load in portrait mode. So add this little bit of code to check the orientation when you start your app and set the it accordingly.

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) 
        Configuration conf = this.getResources().getConfiguration();
    	if (conf.orientation== Configuration.ORIENTATION_LANDSCAPE)
    	else if (conf.orientation== Configuration.ORIENTATION_PORTRAIT)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s