码迷,mamicode.com
首页 > 其他好文 > 详细

今日小结 4.18

时间:2016-04-19 08:39:41      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:

  • 多线程Demo  OK
  • 获取蓝牙数据,显示温度
  • 中期报告

 

1.post 张贴;发帖子,挂在网上;邮件,邮寄;标杆,柱子。

相似的有 pending 未决定的,悬而未决的,挂起的(还未执行,即将执行的),搁置的

pending表状态,表明事件是挂起的,还未执行但即将执行的

post 表动作, 一般指“挂到”事件队列中,表动作

(ex1)

If the current thread is not the UI thread,         //如果当前线不是UI线程(主线程),则
the action is posted to the event queue of the UI thread.  //这个事件将被挂在UI线程的事件队列  //队列就是排队买饭,先到先吃,后到后吃,所以这个新到的事件会被排在(挂在事件队列的最后,就像被post ,被贴上去一样)
    /**
     * Runs the specified action on the UI thread. If the current thread is the UI
     * thread, then the action is executed immediately. If the current thread is
     * not the UI thread, the action is posted to the event queue of the UI thread.
     *
     * @param action the action to run on the UI thread
     */
    public final void runOnUiThread(Runnable action) {
        if (Thread.currentThread() != mUiThread) {
            mHandler.post(action);
        } else {
            action.run();
        }
    }

 

(ex2)

延时挂起 postDelayed 

即执行到这个handler时,将事件r 加入消息队列,延时2000ms后再挂到当前线程中的事件队列

public final boolean postDelayed (Runnable r, long delayMillis)
Added in API level 1
Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses. The runnable will be run on the thread to which this handler is attached. The time-base is uptimeMillis(). Time spent in deep sleep will add an additional delay to execution.
        /*开线程*/
        new Handler().postDelayed(new Runnable() {          //使任务延时执行
            @Override
            public void run() {
                Log.d("mylog","进入了run(),开始loadData()");
                mainPresenter.loadData();
                Log.d("mylog","loadData() 结束");
            }
        },2000);

 

今日小结 4.18

标签:

原文地址:http://www.cnblogs.com/Chongger/p/5404665.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!