Android Question android.os.NetworkOnMainThreadException, IoIo-Board

Discussion in 'Android Questions' started by kje, Feb 6, 2014.

  1. kje

    kje New Member Licensed 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?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You can set the target version to 8 instead of 14 in the manifest editor. It will prevent this error.
     
    kje likes this.
  3. kje

    kje New Member Licensed User

    Thanks. It really works.
    I would have had never a chance on my own.
     
  4. Ronnie

    Ronnie New Member Licensed 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 ?
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    It is better not to limit the question to a single member.

    You should use AsyncStreams to manage the communication.
     
  6. Ronnie

    Ronnie New Member Licensed User

    Noted and thanks for the tip.
     
  7. Loris Anoardi

    Loris Anoardi Member Licensed User

    great ! with target version 8 it works!!! i got the error only in release, not in debug
     
  8. Erel

    Erel Administrator Staff Member Licensed User

  9. Loris Anoardi

    Loris Anoardi Member Licensed 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
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice