Reputation: 1
I have an issue with a game I've been making for Android with Air. 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.
EDIT: I've just made an important discovery! It seems this is dependant on what kind of lock screen you use on your phone. I use an android 4 galaxy s3. I switched it to not use a lock screen and the app stayed in landscape when I unlocked! This is progress. Unfortunately my friend who has a different android 4.0 phone has reported the same issue so it's not just my phone.
Upvotes: 0
Views: 3469
Reputation: 43
My mobile game android app should be in landscape mode, when I maximize after minimize the app it will display in landscape mode and screen not rotated, but the problem is height and width are interchanged. So it was displayed half of the screen only remaining was blank screen. If we lock and unlock the device, automatically the height and widths are fit according to screen size.
I handled the above problem using Event.ACTIVATE, if app is active then i reset the width,height,scaleX and scaleY. In 4.0, 4.1, 4.2 versions of android it is working fine but when we used 4.4, 5.1 it will shows same problem. How can we rectify this ?
Upvotes: 0
Reputation: 1
I guess it's an old thread but I have just had this same problem myself and this is what seemed to solve the issue for me. An extra listener is somewhat crude but it works.
var default_orientation:String;
default_orientation=stage.orientation;
stage.addEventListener(Event.ENTER_FRAME,check_if_stage_is_rotated);
function check_if_stage_is_rotated(e:Event):void{
if (stage){
if(stage.orientation!=default_orientation){
stage.setOrientation(default_orientation);
}
}
}
Upvotes: 0
Reputation: 1
After a bunch of mucking around, I have found a simple solution that works reliably on my devices. Basically just listen for the application being activated and then reset the orientation to what you want it to be.
NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, onDeactivate);
private function onDeactivate(e:Event):void
{
this.addEventListener(Event.ACTIVATE, onActivate);
}
private function onActivate(e:Event):void
{
this.removeEventListener(Event.ACTIVATE, onActivate);
if(stage.deviceOrientation == StageOrientation.ROTATED_RIGHT)
stage.setOrientation(StageOrientation.ROTATED_LEFT);
else
stage.setOrientation(StageOrientation.ROTATED_RIGHT);
}
Upvotes: 0
Reputation: 1
I've been having exactly the same problem.. to the point that I decided to roll with the punch and rebuilt my game to a fluid layout and everything gets repositioned and resized. Overall, it worked, but I would have preferred to stay landscape. I don't think it's a Google thing, I think it's a Flash CS6 issue. This bug doesn't happened when I publish in CS5.5, however I got CS6 because I could integrate the AIR into my game. I'm not sure why, but that's my observations.
Upvotes: 0
Reputation: 3190
I have the same issue. I've tested on a few different devices. Most of them actually crash or gain extreme lag if the lock screen requires a password. My solution allows auto-orientation after the device falls asleep, and then disables it again once the device is in Landscape. I hide all of my content while the device is in portrait. FYI I have not tested all of this code yet, so it may be missing something.
//Before the device goes to sleep, enable auto-orientation
NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate, false, 0, true);
function handleDeactivate(e:Event):void
{
stage.autoOrients = true;
//listen for the device to re-activate
e.currentTarget.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true);
}
//Once the device is re-activated, check the orientation.
function handleActivate(e:Event):void
{
e.currentTarget.removeEventListener(Event.ACTIVATE, handleActivate, false, 0, true);
//if the orientation is portait, just listen for an orientation change
if (stage.stageHeight > stage.stageWidth)
{
//It makes sense that you would just use stage.setAspectRatio(StageAspectRatio.LANDSCAPE) here,
//however in my experience I've found that setting the aspect ratio here seems to cause an infinite loop of the device attempting to reset the orientation.
//Instead, I will wait for the user to change orientation, and then lock it in landscape
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, onOrientationChange);
}
else
{
disableAutoOrientation();
}
}
//Check if the new orientation is landscape. If so, disable orientation changes.
function onOrientationChange():void
{
if (stage.stageWidth > stage.stageHeight)
{
stage.removeEventListener(StageOrientationEvent.ORIENTATION_CHANGE, onOrientationChange);
disableAutoOrientation();
}
}
//disable the auto-orientation feature
function disableAutoOrientation():void
{
stage.autoOrients = false;
}
Upvotes: 2
Reputation: 33
I had the same problem for ages aswell regarding the forced portrait behaviour after resuming from the lockscreen I used something like this which seems to work:
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, onOrientationChange, false, 0, true);
private function onOrientationChange():void
{
if (stage.stageWidth > stage.stageHeight)
{
stage.setAspectRatio(StageAspectRatio.PORTRAIT);
}
else
{
stage.setAspectRatio(StageAspectRatio.LANDSCAPE);
}
}
although I'm not sure what would happen if a device reported stageWidth as the longer side and stageHeight as the shorter side i.e. do all devices report the orientation as we would expect it to
Upvotes: 0
Reputation: 1094
I'm butting heads with the same problem, here's my infodump on the subject.
As far as I can see, the cause is that the lock screen is an overlay on the main screen, so to show the lock screen, the display is activated, along with your application (it receives 'activate' event and starts running). If the device defaults to portrait orientation on the lock screen (phones mostly do, tablets mostly don't) your application is dragged along for the ride, regardles of its preferences and AIR manifest wishes.
As a result, when your app finally gets to the foreground (user unlocks the screen) it is portrait oriented. The workaround is to manually set the desired orientation when you recieve activate event. There's an added quirk on ICS - system notification bar reappears after unlock (no fullscreen anymore), and re-setting stage to fullscreen has no effect. And that's as far as I managed to get. Would appreciate a notice if you find a solution.
A related problem is that when lock screen is displayed, your game starts to run underneath, which is bad situation if, for example, it's an action game and you stopped in the middle of something that required immediate input (like, anywhere in the game :-)). Would love to find a solution to that.
Upvotes: 0
Reputation: 4340
Put this to app descriptor xml
<aspectRatio>portrait</aspectRatio>
<autoOrients>false</autoOrients>
Upvotes: 2