Android Question android.os.NetworkOnMainThreadException, IoIo-Board

kje

Member
Licensed User
Longtime User
I have written two apps:

One for uploading data to a server via FTP.Upload controlled by a timer. It works fine
Another one to retrieve data from a IoIo-Board. Works also fine.

Combining the codes of both to upload the measured data I'm getting the "android.os.NetworkOnMainThreadException" as soon the app reaches the statement: YOYO.WaitForConnect() which comes directly after YoYo.initialize(false)) in Activity_create(...).

How to avoid the exception?
 

Ronnie

New Member
Licensed User
Longtime User
Hi Erel,
I started trying to learn Android apps development using the tools from Google and after going through the tutorials there, I almost gave up. I figured there has to be a better, more efficient way to do it and I stumbled (thanks to Google search) upon Basic4android. I downloaded the eval and after 1 hour I was back at Anywhere Software - to purchase a licensed copy. It's fantastic what you guys have done to make Android development so easy.

I was writing a network app to connect to a serial device server using TCPIP protocol and I hit the same error as kje. The program ran fine on my Galaxy S (2.3.3) but crashed on my Note 2 (4.3). I'm about to try setting the target to 8 instead of 14 but I have the following questions :

1. Would that mean I can only say the program's been tested at API 8 only ?
2. Is there some new security stuff that is enforced in 4.3 that causes the exception ?
 
Upvote 0

Loris Anoardi

Member
Licensed User
Longtime User
Hello Erel,
my network calls are managed in a service module (socket server used for receiving messages from a server).
How can i use a separate thread?
Is there an example?
thanks
 
Upvote 0
Top