I’m working on a multiplayer android game using SpiderMonkey.
However,network crashes and console returns this error:
android.os.NetworkOnMainThreadException
Lurking on the internet i found some docs talking about the AsyncTask class on Android’s API. It has to be used as Android>3.0 doesn’t support networking on main thread.
However i don’t know how to implement this in a JME game using SpiderMonkey. I’m pretty sure there’s a way to solve this issue but i can’t find it.
Before everyone can ask,yes,i added those lines to manifest:
From the client, I think the initial connection happens on the thread you open the connection. The message processing happens on a separate thread but connect() tries to do the actual socket hookup so that you get host not found errors, etc. right away. (That’s my recollection.)
AsyncTask is only used for things that need the UI thread from what I understand.
You should be able to use standard Java threading classes to do this.
Start a new thread to create the connection then wait for it to exit. Or use an Executor and then shut it down when done.