Android Orientation bug onResume #1662

Closed
Maigre opened this Issue Oct 21, 2012 · 17 comments

4 participants

@Maigre

Hi,
here is the problem:

with all Examples (and also my app since i'm starting from empty example),
on first start, orientation change works well. I can start in Landscape, move the device, orientation will follow.

The problem occur when the App go in Pause (quitting with Home button for exemple):
when i resume the App (from menu or from history stack), the orientation is Locked in Portrait !!
Even if i was resuming it in Lnadscape, and even if i turn the device, it is locked in Portrait...

To be back on normal operation, i need to quit the App, call the history stack, remove the App
to actually close it for real, and then relaunch it, and the orientation will work fine again...

Why the Orientation is locked in Portrait after Pause and Resume ??

I got the same problem with both Real and Virtual Devices,
in different resolution, with API 8, 15 and 16 ...

Thanks for your Work

Best Regards

Thomas

@bilderbuchi
openFrameworks member

Thank you for your bug report and repro procedure! What OF version were you using? If it's 0072, did this work with a previous version?
@arturoc any idea what could be wrong here?

@Maigre

Hi, sorry i'm new on Android dev, so i don't know where it could come from...
I tried with both 0072 and master git branch.

If you set orientation to Landscape in the Manifest, the problem is the same:
the app start in Landscape, that's ok, but is locked in Portrait after pause / resume.
The problem is overriding the Manifest.

I tried to dig into onResume code, to see if there is not a position set somewhere,
but i did not find anything...

@bilderbuchi
openFrameworks member

Thanks.
By previous version, I meant 0071 (you can do git checkout 0071 to get the 0071 version easily).

@Maigre

Ok, i'm trying to compile 0071 but i got arm-linux-androideabi-g++ missing (using NDK r8 and r8b)
I struggle with those toolchain stories ! (i learning it the hard way ;)

EDIT: with NDK r7b (which include g++) i have the following error :
Erreur fatale: option -march= invalide: « armv5te »

@bilderbuchi
openFrameworks member

ok, that's what I feared - 0071 probably not compatible with the current android packages. I fear I can't suggest anything else, I'm outof my depth. let's wait until arturo or someone else can contribute.

@danzeeeman
openFrameworks member

I saw this bug on the develop branch a couple weeks ago. I was trying to turn off Auto rotation and it kept coming back after the onResume but I was able to get around it and make my App listen to me. I will try to reproduce it.

@Maigre

Ok, so i'm not the only one having this problem ;)
Any idea on which part of the framework I have to look for this ?
@arturoc any clue to help us find the bug?
Thanks!

@arturoc arturoc closed this in 87cbf1b Oct 30, 2012
@arturoc
openFrameworks member

that should fix it

@Maigre

@arturoc Problem not fixed !

Even with OFAndroid.setScreenOrientation(90); in the resume() function i have the same problem:
when i start the app, it is forced to landscape, that's ok, but when i pause (home) and come back
i'm forced in Portrait again !!

EDIT: see here http://youtu.be/UZBGjZlsOwE

@danzeeeman
openFrameworks member

so I had to make changes in the manifest to set Activity's orientation to what I wanted via this attribute in the XML android:screenOrientation="landscape" and then in my void setup() in the CPP ofSetOrientation(OF_ORIENTATION_90_LEFT) that solved the issue and it launches in the landscape mode every time.

@Maigre

Doesn't work for me even if i force orientation in the resume() java function.
It works on first start and every start if i remove the app from history stack,
but if i just resume when paused, it is still locked in Portrait !
Here is a video to demonstrate my problem :

http://youtu.be/UZBGjZlsOwE

Thanks for your help !

@danzeeeman
openFrameworks member

So we shouldn't be setting the orientation programmatically at the java level. It causes all kinds of problems. We should be setting the orientation in the manifest. Please check what you have listed in the activity section for the screenOrientation as it should be one of the following. Also we have to change the orientation at the CPP level to change the coordinate system, you should use the ofSetOrientation() call in your CPP to manage the orientation of the objects you are drawing on the screen.

android:screenOrientation=["unspecified" | "user" | "behind" |
"landscape" | "portrait" |
"reverseLandscape" | "reversePortrait" |
"sensorLandscape" | "sensorPortrait" |
"sensor" | "fullSensor" | "nosensor"]

@Maigre

Ok, i was sure i tried this in the first place...
but i just tried it again and it's now working with Poylgon example...
i'll try it with my app and let you know if it is ok.

Thanks !

@danzeeeman
openFrameworks member

@arturoc you should revert those changes and I should do an example for the repo on how to setup the orientation correctly.

@arturoc arturoc reopened this Oct 30, 2012
@Maigre

Ok with,
android:screenOrientation="landscape" in the manifest
and
ofSetOrientation(OF_ORIENTATION_90_LEFT) in the setup of my app (CPP)
it works: i can pause and resume and the app stay in LandScape.
Thanks for that !

Still buggy:
if you don't specify any orientation with ofSetOrientation()
The orientation will be in locked in Portrait after pause and resume,
no matter what you specified in the manifest.
So it might be a problem if you want to use Sensor oriented app.

Best Regards,
Thomas

@danzeeeman
openFrameworks member

OK we might need an event that gets tossed down from the JAVA to the CPP to handle screen rotations. So currently in the CPP if ofSetOrientation(fooBar) isn't called it defaults to OF_ORIENTATION_DEFAULT and that gets set at Java_cc_openframeworks_OFAndroid_onSurfaceCreated() in ofAppAndroidWindow.cpp. In the JAVA we never actually make the call to CPP to change the oF orientation we just setup the Activity in OFAndroid.java using the setScreenOrientation(int orientation) method. So I guess the problem is that when we change the Orientation of the Activity in the JAVA layer it is never getting communicated to the CPP layer.

@arturoc arturoc added a commit that closed this issue Nov 4, 2012
@arturoc arturoc android: don't set orientation from cpp on resume,
so java only sets it if it's been set programatically.
Closes #1662
23a4f89
@arturoc arturoc closed this in 23a4f89 Nov 4, 2012
@arturoc
openFrameworks member

ok, that fixes it, now if you set the orientation from the manifest it'll work even when resuming and if you set the orientation programmatically it'll work and stay in that after resuming too. also fixes when no orientation is set

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment