Android: orientation (landscape / portrait) to start activity

My activity should control the orientation of the device. Now this works fine with onConfigurationChanged(), but I also need to know the orientation when my activity starts.

So, how do I know the current orientation of the device in mine onCreate(), for example?

+3
source share
1 answer

I am not an 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);
}                           
+20
source

Source: https://habr.com/ru/post/1762027/


All Articles