zoukankan      html  css  js  c++  java
  • android 线程的使用总结

    //标识位的设定
    boolean flag=false;
    消息的接受,UI更新或者文本更新;
        Handler handler=new Handler(){
            @Override
            public void handleMessage(@NonNull Message msg) {
                if(msg.what==0x01){
                    textView.setText((String)msg.obj);
                }
            }
        };
    //UI的初始化
    flag=true;
    new Thread(){
                @Override
                public void run() {
                    super.run();
                    while(flag){
                        SimpleDateFormat format=new SimpleDateFormat("yyyy年MM月 HH:mm:ss");
                        String timeStr =format.format(System.currentTimeMillis());
                        Message msg=new Message();
                        msg.what=0x01;
                        msg.obj=timeStr;
                        handler.sendMessage(msg);
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }.start();
    线程的销毁(关闭);
        @Override
        protected void onDestroy() {
            super.onDestroy();
            flag=false;
        }
    
  • 相关阅读:
    meta标签
    Vue(day8)
    Vue(day7)
    Vue(day6)
    Flex布局
    Vue(day5)
    jquery.data()&jquery.extend()
    Promise对象
    Vue(day4)
    Vue(day3)
  • 原文地址:https://www.cnblogs.com/HE-helloword/p/13519681.html
Copyright © 2011-2022 走看看