在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            android 線程通信

            作者: 時間:2016-10-08 來源:網(wǎng)絡(luò) 收藏

            activity_main.xml

            本文引用地址:http://www.biyoush.com/article/201610/305984.htm

            xmlns:tools=http://schemas.android.com/tools

            android:layout_width=match_parent

            android:layout_height=match_parent

            android:paddingBottom=@dimen/activity_vertical_margin

            android:paddingLeft=@dimen/activity_horizontal_margin

            android:paddingRight=@dimen/activity_horizontal_margin

            android:paddingTop=@dimen/activity_vertical_margin

            tools:context=.MainActivity >

            android:id=@+id/button1

            android:layout_width=wrap_content

            android:layout_height=wrap_content

            android:layout_alignParentLeft=true

            android:layout_alignParentTop=true

            android:layout_marginTop=16dp

            android:text=通信 />

            MainActivity.java

            public class MainActivity extends Activity implements OnClickListener{

            Handler mainHanler,subHandler;

            Button btn1;

            @Override

            protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.activity_main);

            initViews();

            mainHanler = new Handler(){

            @Override

            public void handleMessage(Message msg) {

            super.handleMessage(msg);

            if(msg.what == 1){

            System.out.println(msg.obj.toString());

            }

            }

            };

            new WorkThread().start();

            }

            public void initViews(){

            btn1 = (Button) findViewById(R.id.button1);

            btn1.setOnClickListener(this);

            }

            @Override

            public void onClick(View v) {

            switch (v.getId()) {

            case R.id.button1:

            //交互

            Message msg = Message.obtain();

            msg.what = 1;

            msg.obj = 兒子,哥來看你啦!;

            subHandler.sendMessage(msg);

            break;

            }

            }

            public class WorkThread extends Thread{

            @Override

            public void run() {

            Looper.prepare();

            subHandler = new Handler(){

            @Override

            public void handleMessage(Message msg) {

            if(msg.what == 1){

            //接受消息

            System.out.println(msg.obj.toString());

            }

            //發(fā)消息給主線程

            Message m = Message.obtain();

            m.what = 1;

            m.obj = 老爸我來啦!;

            mainHanler.sendMessage(m);

            }

            };

            Looper.loop();

            }

            }

            }



            關(guān)鍵詞:

            評論


            相關(guān)推薦

            技術(shù)專區(qū)

            關(guān)閉