Change elements on the UI thread with data received in onEvent using AndroidAsync's SocketIOClient

StackOverflow https://stackoverflow.com/questions/23274756

Domanda

I can see emitted messages from the server in the Android app's console log using System.out. How do I actually use this new data to change things in my UI though?

I have tried setText on a TextView that I got a handle to in onCreate. No error is thrown but nothing actually happens.

I also tried making a Toast but I get an error java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare().

È stato utile?

Soluzione

That error is saying that you are trying to change the UI(Toast) from a different thread.. if you want to change the UI from a different thread you must call the UI/Main thread first and put it there..

Sample::

runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            //Do the changing of UI here
                        }
                 });
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top