套接字在线程上接收后的活动标题

时间:2019-04-23 12:41:29

标签: java android multithreading sockets

我在使用Android应用程序时遇到问题,它在不同线程上的Socket上监听,并且收到消息后,它分解为String.split,其中一部分字符串应该是Activtity标题,但从未更新。该怎么解决?

activity.runOnUiThread(()-> getSupportActionBar()。setTitle(components [1])); activity.runOnUiThread(()-> setTitle(components [1]));

class updateUIThread实现Runnable {         public String msg;

    public updateUIThread(String str){
        this.msg = str;
    }

    public void run(){
       String components[] = msg.split(":");
        supervisorMessage.setText(String.valueOf(components[2]));
        activity.runOnUiThread(() -> getSupportActionBar().setTitle(components[1]));
        activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#" + components[0])));
    }
}

0 个答案:

没有答案