Linked Questions

Popular Questions

Android Portrait and landscape

Asked by At

I locked my app on portrait mode for mobile devices, and landscape for TV. The issue is, I want it on the whole app. I have multiple activities inside my app, so I have to check every activity for portrait and landscape. Is there a way to make my code global for all the activities? I don't want to write that code in every activity.

Here is my code:

I'm using this before:

setContentView(R.layout.activity_main);

MainActivity.java

// locking out landscape screen orientation for mobiles
if(getResources().getBoolean(R.bool.portrait_only)){
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

// locking out portrait screen orientation for TV
if(getResources().getBoolean(R.bool.landscape_only)){
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}

Related Questions