Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-26157

Android: A semi-transparent or modal Window with a fixed orientation crashes on Android 8

    Details

      Description

      Summary:
      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:

      1. Create a Titanium 7.3.0 project.
      2. Build and run the below code on an Android 8 device.
      3. Note that the app crashes (or hangs) on startup and fails to display the window.
      4. Build and run on an Android 7 or older device.
      5. Note that the app runs just fine.

      var window = Ti.UI.createWindow({
      	opacity: 0.5,
      //	modal: true,
      //	backgroundColor: "rgba(0,0,255,128)",
      	orientationModes: [Ti.UI.PORTRAIT],
      });
      window.open();
      

      Notes:

      • 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 not appear to work-around the issue as suggested by the exception message.

      Reason:
      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.

      java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
      

      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...
      https://stackoverflow.com/questions/48072438/java-lang-illegalstateexception-only-fullscreen-opaque-activities-can-request-o

      Google's code change that introduced this issue can be seen below. See the Java ActivityRecord.setRequestedOrientation() method.
      https://github.com/aosp-mirror/platform_frameworks_base/commit/39791594560b2326625b663ed6796882900c220f#diff-960c6fdd4a4b336d98b785268b2a78ff

      Work-Arounds:

      • 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.

        Attachments

          Activity

            People

            • Assignee:
              jquick Joshua Quick
              Reporter:
              jquick Joshua Quick
              Reviewer:
              Gary Mathews
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-6419
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Source Code