1

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

Community
  • 1
  • 1
dorjeduck
  • 7,624
  • 11
  • 52
  • 66

2 Answers2

0

Try adding this to your manifest:

android:configChanges="keyboardHidden|orientation|screenSize">

This prevents orientation changes on onPause and onResume

Jack Satriano
  • 1,999
  • 1
  • 13
  • 17
  • thx for the feedback John - "keyboardHidden|orientation" I had already, adding screenSize didnt solve the problem - the strange thing is that the problem not always occurs, maybe at 20% of the activity changes ... it seems i am sort of too late to fix the orientation to be sure it is set before the screen is rendered the first time – dorjeduck Sep 23 '12 at 18:08
0

Try this...

<activity android:name="com.myapp.MyActivity"
          android:label="@string/app_name"
          android:configChanges="orientation|screenSize"
          />

for more take a look here.....

http://digitaldumptruck.jotabout.com/?p=897

This may help you.

bashu
  • 1,710
  • 12
  • 16
  • thx Bashu for the answer - this is basically what i am doing already (what is explained in the link you gave) yet somehow it doesnt work in my app right now, some bug in my coding i get the feeling not in the general approach – dorjeduck Sep 23 '12 at 18:20