Details
-
Type:
Bug
-
Status: Closed
-
Priority:
High
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: Release 7.5.0
-
Component/s: Android
-
Story Points:7
Description
Summary:
If the "tiapp.xml" file property run-on-main-thread is set to true, then calling a Ti.Networking.Socket.TCP object's blocking read() or write() method will cause a crash on Android.
Steps to reproduce:
- Open the project's "tiapp.xml" file.
- Make sure property "run-on-main-thread" is set to true.
- Set up an Android device with Internet access.
- Build and run TcpClientBlockingTest.js
on the Android device.
Result:
The app crashes with a Java NetworkOnMainThreadException.
Cause:
The Java java.net.ServerSocket class will throw a NetworkOnMainThreadException when used on the main UI thread. It can only be used by a non-UI thread.
Work-Around:
Simplest solution is to set the tiapp.xml property "run-on-main-thread" to false.
Best solution is to not use the blocking read() and write() methods and use the async Ti.Stream.pump() and Ti.Stream.write() methods instead as documented here...
https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Network.Socket.TCP
Note that even if we do fix the crash, we still don't recommend using the synchronous read() and write() method calls since they'll block the UI thread. This will make the UI appear to stutter or hang, providing a poor experience for the end-user.
Attachments
Issue Links
- relates to
-
TIMOB-26575 Windows: Support async variants of Ti.Network.TCP #read and #write
-
- Closed
-
-
TIMOB-26411 API: Support async variants of Ti.IOStream methods
-
- Closed
-
-
TIMOB-25862 Parity: Support async Ti.UI.Webview.evalJS call on Android & iOS
-
- Closed
-