Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network activity on UI thread on Android #30

Open
dereulenspiegel opened this issue Apr 19, 2013 · 3 comments
Open

Network activity on UI thread on Android #30

dereulenspiegel opened this issue Apr 19, 2013 · 3 comments

Comments

@dereulenspiegel
Copy link

When creating a connection in Android activities in onCreate (like shown here http://jfarcand.wordpress.com/2013/04/04/wasync-websockets-with-fallbacks-transports-for-android-node-js-and-atmosphere/) the exception android.os.NetworkOnMainThreadException is thrown. wasync seems to invoke networking methods not on in a background thread.
While it is possible and trivial to do the connection set up in the background the expectation is that an synchronous librarylike wasync does all networking in a background thread.
This would simplify the usage of this library.

@jfarcand
Copy link
Member

Hi, can you elaborate? wAsync is fully asynchronous, hence I needed to add those android property. How can it be avoided?

@dereulenspiegel
Copy link
Author

On newer versions of Android there is a policy which prohibits all network activity on the UI thread. In case you call any method related to networking like opening sockets or using URLConnection.open an exception is thrown.
It seems that wAsync does some networking on Socket.open before everything else is handled in the background. On other platforms this might not be a problem, but Android is very strict with these things.
Threading in general is a bit tricky, since the results must be delivered back to the UI on the UI thread.
In the long run it could be nice for developers to have some kind of "wrapper" for wAsync on Android which handles threading and delivery of results in the correct threads.

@jfarcand
Copy link
Member

I see. If you have the cycle, do a pull request with your idea and I will start from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants