handler使用方法

  // 听说这是最标准的写法
    MyHandler myHandler = new MyHandler(this);
    static class MyHandler extends Handler{
        WeakReference weakReference;
        public MyHandler(MainActivity activity){
                weakReference=new WeakReference(activity);
        }

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case REFRESLAYOUT:
                    LogUtil.e("10s打印一次");
                    sendEmptyMessageDelayed(REFRESLAYOUT, 10000);
                    break;
            }
        }
    }

参照的以下网址   https://blog.csdn.net/androidsj/article/details/79865091

posted @ 2020-05-29 11:21  码弄  阅读(389)  评论(0编辑  收藏  举报