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

Android: ImageView "image" set to a URL while "autorotate" is true will crash if running on main thread

    Details

    • Story Points:
      7
    • Sprint:
      2018 Sprint 16 SDK

      Description

      Summary:
      The Android ImageView will cause a crash if you set "image" to a URL, "autorotate" to true, and the JavaScript runtime is set up to run on the main UI thread.

      Steps to reproduce:

      1. Uninstall the app from the device if already installed. (Will delete cached web responses.)
      2. Make sure the Android device has Internet access.
      3. Set "tiapp.xml" file property "run-on-main-thread" to true.
      4. Build and run the below code.
      5. Notice that the app crashes/hangs on app startup.

      tiapp.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <ti:app xmlns:ti="http://ti.appcelerator.org">
      	<property name="run-on-main-thread" type="bool">true</property>
      </ti:app>
      

      app.js

      var window = Ti.UI.createWindow();
      window.add(Ti.UI.createImageView({
      	image: "https://raw.githubusercontent.com/recurser/exif-orientation-examples/master/Portrait_3.jpg",
      	autorotate: true,
      }));
      window.open();
      

      Cause:
      When the ImageView property autorotate is set to true, it will attempt to read the image's EXIF rotation if applicable. Since the image file is not in storage, it will attempt to re-download the image on the main UI thread, but Android's Java HttpUrlConnection class will throw a NetworkOnMainThreadException when attempting to do so.

      Work-arounds:
      You can do one of the following to work-around this issue...

      • Set "tiapp.xml" property "run-on-main-thread" to false.
      • Download the image file to storage via HTTPClient and display the download file instead of a URL.
      • Set ImageView property "autorotate" to false.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

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

                  Git Source Code