Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

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

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2018-08-24T01:15:45.000+0000
Affected Version/sn/a
Fix Version/sRelease 7.5.0
ComponentsAndroid
LabelsImageView, android, url
ReporterJoshua Quick
AssigneeJoshua Quick
Created2018-07-31T22:53:02.000+0000
Updated2018-08-24T01:15:49.000+0000

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

Uninstall the app from the device if already installed. (Will delete cached web responses.)

Make sure the Android device has Internet access.

Set "tiapp.xml" file property "run-on-main-thread" to true.

Build and run the below code.

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.

Comments

  1. Joshua Quick 2018-08-01

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/10222
  2. Samir Mohammed 2018-08-14

    Closing ticket as fix has been tested as part of TIMOB-24605.

JSON Source