Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Getting orientation (landscape/portrait) on Activity launch

Tags:

android

My Activity needs to monitor the orientation of the device. Now this works great with onConfigurationChanged(), but I also need to know orientation when my Activity starts.

So how do find out the current orientation of the device in my onCreate(), for instance?

like image 520
Alex Wayne Avatar asked Nov 29 '22 19:11

Alex Wayne


1 Answers

I'm no expert but this works for me, in onCreate():

int display_mode = getResources().getConfiguration().orientation;

if (display_mode == Configuration.ORIENTATION_PORTRAIT) {
    setContentView(R.layout.main);
} else {
    setContentView(R.layout.main_land);
}                           
like image 184
ShadowGod Avatar answered Dec 05 '22 05:12

ShadowGod