Android: Device rotation doesn't work starting with build 2011.641

I just noticed that device rotation on Android doesn’t work properly with the latest daily builds. It worked fine with 2011.639 to 640.

One thing to note is that the problem only happens when running on a device. Rotation works fine in the simulator.

What happens with build 641 and onwards is that the screen rotates to its new orientation, and immediately rotates back to its original orientation, leaving it upside down.

Just to clarify: This is only an issue on Android. Rotation on iOS works fine with the latest builds…
[import]uid: 70847 topic_id: 16688 reply_id: 316688[/import]

ingemar,

I just tried the following samples apps with build 644 and I was not able to reproduce your issue:

  • Graphics\Fishies
  • Interface\NativeDisplayObjects

Both of the above apps handle orientation changes, but do it in different ways. Namely, the “Fishies” sample app has a fixed orientation and handles rotations itself when it receive orientation events from Android.

Would you mind attempting to reproduce this issue with the above sample apps on your device? That will help us isolate this issue. Thanks! [import]uid: 32256 topic_id: 16688 reply_id: 62435[/import]

Hmmm. Yeah, both of them work.

The fishies app becomes a little funky though when trying to change orientation 180 degrees (or if another orientation change is made before the animation has come to a stop), but I think that may be just a buggy implementation…

At least I’m not seeing the behavior I’m having in my app.
I’m going to have a look at the code that does the orientation changes in my app. I’m using a library from the code exchange which has worked fine so far (and still does for iOS, which is weird).

I’ll post my findings here once I have more info… [import]uid: 70847 topic_id: 16688 reply_id: 62447[/import]

If your app worked with build #640, then naturally I’m concerned that we might have broken something in Corona. If you can help us reproduce this isolate this issue then that would be greatly appreciated. The release notes on the daily builds might clue you in on what has changed since then.

One thing to note. The Android operating system has special handling for 180 degree orientation changes (from landscape-left to landscape-right and vice versa). The OS will actually flip the surface but not send an orientation change event to Corona. Since Corona does not receive the orientation event from the OS, the Lua orientation event listener doesn’t receive it either. It’s an unfortunate limitation in Android (probably done for performance reasons) and it has always been an issue for apps set up to support both portrait and landscape orientations. You’ll see this behavior in the “NativeDisplayObjects” sample app since it display the app’s current orientation.

That said, as of the newest daily builds, you can work-around the above Android 180 degree limitation by setting up your app with fixed orientation (locked to portrait or landscape left). This is how the Fishies sample app works and notice that it always receives all orientation events. This is because Corona listens to the accelerometer in this case to determine the device’s current orientation itself.

Regarding rotating the screen too quickly on “Fishies” sample app, that is a known issue in the sample code. It is not an issue in Corona itself.

I hope this helps. [import]uid: 32256 topic_id: 16688 reply_id: 62453[/import]

I’ve found the reason :slight_smile:

In build 2011.639 and 640 system.orientation reported the actual orientation the device was in. In this case I only cared about ‘landscapeRight’ and ‘landscapeLeft’.

From build 641 and onwards it only reports ‘landscapeRight’, even though the device is in landscapeLeft.
I saw that the documentation states that Android only reports ‘portrait’, and ‘landscapeRight’, however it wasn’t always like this.

Actually it’s no big problem, I’ve re-written my code to take care of this, and the documentation is clear about this limitation. [import]uid: 70847 topic_id: 16688 reply_id: 62622[/import]

That sounds like a bug to me. Although I know we’ve tested this with via the NativeDisplayObjects sample app, which display the current state of “system.orientation” onscreen.

Is your app set up for both landscapeLeft and landscapeRight… and not portrait? What was system.orientation outputting before? [import]uid: 32256 topic_id: 16688 reply_id: 62721[/import]

I just had a look at NativeDisplayObjects, and the label doesn’t reflect the value of system.orientation, it prints the value of event.type (line 605 in main.lua)

If you change line 605 to display system.orientation instead, you’ll see what I mean.

On Android system.orientation doesn’t change value from the initial value it got from app launch.
On iOS it works fine.

However, the orientation returned by event.type is correct. [import]uid: 70847 topic_id: 16688 reply_id: 62734[/import]

I wrote up a bug report for this issue so that it can be taken care of sometime in the near future. Thanks for the details. It was a big help. [import]uid: 32256 topic_id: 16688 reply_id: 63179[/import]

This bug is now fixed. The system.orientation property now provides the correct orientation value. This fix will be made available in build #697. [import]uid: 32256 topic_id: 16688 reply_id: 70485[/import]

Great.
Thanks! [import]uid: 70847 topic_id: 16688 reply_id: 70523[/import]