my program is supposed to run on landscape so in the manifest i used android:screenOrientation="landscape"
, recently i got a device that should work in portrait, i made a few changes on the code and added a gui landscape and portrait, in my setting page i added a checkbox where it ask if should run in vertical or landscape...
now i have the problem if i remove on the manifest the screenorientation i can't manually force it in the code, i tried to use
if (prefs.getBoolean(Settings.ORIENTATION_KEY, false)) {
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
else
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
but this partially works, the activity is created first on portrait (or the current phone rotation) and then rotated in the right direction, this make the app crash because in portrait i have differents keys and most important thing i see the activity that get launched first in portrait then closed and launched again in landscape...
all this just for ask, is possible to set the orientation before the onstart (like manifest) but with a value from a saved value? i saw that i can use build.gradle for make some kind of var in the manifest, but i don't know how get the value from my settings file (i use getSharedPreferences on code)