An app targeting API Level 26 (aka: Android 8.0) or higher will crash with an IllegalStateException when opening a fixed orientation window (ie: portrait-only or landscape-only) using properties:
- opacity set to any value, including 1.0
- modal set to true
- backgroundColor with semi-transparency such as "rgba(255,0,0,138)"
Steps to reproduce:
- Create a Titanium 7.3.0 project.
- Build and run the below code on an Android 8 device.
- Note that the app crashes (or hangs) on startup and fails to display the window.
- Build and run on an Android 7 or older device.
- Note that the app runs just fine.
- This issue only happens when targeting API Level 26+, which Titanium does by default as of v7.3.0.
- This issue can also be reproduced by using a semitransparent backgroundColor as well.
- You "can" use the opacity or modal property as long as you never use the orientationModes property.
- You "can" use the orientationModes property as long as you never use the opacity or modal properties.
- Setting the fullscreen property to true does appear to work-around the issue as suggested by the exception message.
Google has introduced a breaking change where you can no longer assign an orientation to a "translucent" activity window. Setting the modal and opacity properties causes Titanium to use a translucent themed activity window. Calling the Java setRequestedOrientation() method on such a window will cause the following exception to be thrown.
Note that this is not an issue if the app targets API Level 25 or lower on an Android 8 device. But lowering the API Level is not a valid work-around since Google Play will soon reject apps which do not target Android 8.
This issue can be seen happening to other native Android devs here...
Google's code change that introduced this issue can be seen below. See the Java ActivityRecord.setRequestedOrientation() method.
- If you need to use the orientationModes property, then you cannot use the modal or opacity properties.
- If you need to use the modal or opacity properties, then you cannot use the orientationModes properties, which means the window will support all orientations.
- No other work-around is known for the moment... other than to mock your own modal/semitransparent window using views instead.