my latest (and first) android application gives the user the choice in the preferences to fix the screen to portait or landscape orientation or let the orientation be determined by the sensor. In order to react on the users preferences I have something like
public static void setOrientation(Activity a,int orientation) {
switch (orientation) {
case (1): {
a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
break;
}
case (2): {
a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
break;
}
case (3): {
a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
break;
}
}
}
which I call at onCreate/onRestart to set the orientation accordingly.
The problem I am facing now is that when the user switches from one activity to the next (with a fixed orientation chosen) sometimes the screen is still oriented according to the sensor for a split of a second before the screen is taking the orientation as requested. Is there a way to totally switch off the sensor when the user chooses a fixed orientation. I tried to add
a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
yet so far no success. I am pretty sure I oversee something obvious, any revelation how to achieve the fixation of the orientation dynamically would be highly appreciated.
Thanks a lot
martin
Edit:
I rephrased the question in a new post:
android - unexpected brief orientation change at switch of activity