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

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

문제

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().

도움이 되었습니까?

해결책

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
                        }
                 });
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top