Skip to main content
Inspiring
July 10, 2012
Question

Orientation problem after the phone is being locked

  • July 10, 2012
  • 1 reply
  • 750 views

I have an issue with a game I've been making for Android in Flash. The app orients itself correctly (staying in landscape) up until I lock the phone I'm testing with and then unlock it. When the phone unlocks, the app will then be in portrait mode (it should always be in landscape).

In the descriptor xml file I have set fullscreen to true, aspect ratio to landscape and auto orient to false, but this doesn't seem to affect the app when being locked and unlocked (it works perfectly in any other scenario). It will become portrait again and not move back to landscape when unlocked (so auto orient being false definitely isn't being meddled with).

This issue only triggers when you're running the game and lock the phone and unlock. If for example you were to press the home button so the app is no longer in focus, then lock and unlock and get back into the paused game it will still be in landscape.

I've never had this problem on devices with android 2.3, but after the update to the ICS, I can't find the way to fix it.

Any workarounds?

This topic has been closed for replies.

1 reply

Known Participant
July 11, 2012

Sounds like the lock screen is changing your supposedly locked orientation and not setting it back.

With the games I work on we've always left auto-orient on so I've not played with locking the orientation.

You might try setting the orientation when you get your ACTIVATE event like so:

stage.setOrientation(StageOrientation.DEFAULT);

The problem I've found is that devices don't all standardize to default = portrait.

So first, when your app starts in landscape mode, read out the stage.orientation string and save it.

Next you might need to listen for the orientation change event and then try to find a way to force the orientation back.

Something like:

stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, onOrientationChange);

public function onOrientationChange(event:StageOrientationEvent): void {

     isPortraitView = (stage.fullScreenWidth < stage.fullScreenHeight);

     if (isPortraitView) {

          stage.SetOrientation(mySavedOriginalOrientationState);

     }

}

I hope this helps. Good luck.