Question

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

Was it helpful?

Solution

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
                        }
                 });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top