I have been working on a radio app and along the way i decided to force only landscape to appear for tablets and portrait mode for phones. Here is what i have done so far to achieve that.
First i put a bool resource in res.values to check for screen size.
// From my res/values/bool.xml(sw600 and 720)dp.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="landscape_only">true</bool>
</resources>
// res/values/bool.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="portrait_only">true</bool>
</resources>
I then forced the requested screen orientations with code by checking the boolean in Main Activity.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// locking out landscape screen orientation for mobiles
if(getResources().getBoolean(R.bool.portrait_only)){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
// locking out portait screen orientation for tablets
if(getResources().getBoolean(R.bool.landscape_only)){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
}
}
So far, this worked pretty well. Now here's the issue i have.
When i implemented my code to lock out portrait mode for tablets my app started in portrait for a few seconds before switching to landscape. How do i make sure that it doesn't start off first in portrait? It should start off in landscape.