[TIMOB-26249] Android: ImageView "image" set to a URL while "autorotate" is true will crash if running on main thread
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-08-24T01:15:45.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 7.5.0 |
Components | Android |
Labels | ImageView, android, url |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2018-07-31T22:53:02.000+0000 |
Updated | 2018-08-24T01:15:49.000+0000 |
Description
*Summary:*
The Android Set "tiapp.xml" file property "run-on-main-thread" to
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
.
PR (master): https://github.com/appcelerator/titanium_mobile/pull/10222
Closing ticket as fix has been tested as part of TIMOB-24605.