anismiles / websocket-android-phonegap

This is a Java library that implements Websockt API (Draft-75/76) for Android platform. Library uses java.nio.* packages for efficient non-blocking evented behavior. It easily gets integrated with Phonegap framework.
http://wp.me/pVyFz-qO
MIT License
322 stars 137 forks source link

WebSocket violates the single-threaded model for the UI #3

Closed jeremycw closed 13 years ago

jeremycw commented 13 years ago

The UI can't be touched by anything other than the main thread so loadUrl can't be called directly from onMessage instead you must do this:

public void onMessage(String msg) { final String data = msg; appView.post(new Runnable() { public void run() { appView.loadUrl(buildJavaScriptData(EVENT_ON_MESSAGE, data)); } }); }

or else you will sometimes get CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views

anismiles commented 13 years ago

Thanks. I will do this.

anismiles commented 13 years ago

Fixed!