Question about Android runnable

I saw a piece of code online. I am wondering why we need to use runnable to set TextView text? Thank!

    while (true) {
    // listen for incoming clients
    Socket client = serverSocket.accept();
    handler.post(new Runnable() {
        @Override
        public void run() {
            serverStatus.setText("Connected.");
        }
    });

http://thinkandroid.wordpress.com/2010/03/27/incorporating-socket-programming-into-your-applications/

+3
source share
2 answers

, ? UI - . , . , , - UI (, serverStatus), . .

. UI , . , , , Runnables.

( ), : http://developer.android.com/guide/appendix/faq/commontasks.html#threading

+7

Source: https://habr.com/ru/post/1781550/


All Articles