handler asynchronous communication

handler asynchronous communication

1. Main thread

//handler 异步通信
    private Handler myHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == MESSAGE_KEY) {
                GTCid  =  msg.obj.toString();
                Log.e("gaoyu", "返回里面收到的是" +GTCid);
            }
        }

    };

2. Asynchronous thread

 Message msg = new Message();
            msg.what = MESSAGE_KEY;//用于区分不同的消息
            msg.obj = clientid;//消息内容
            myHandler.sendMessage(msg);//发送消息

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325476450&siteId=291194637