日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內(nèi)最全IT社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當前位置:首頁 > php開源 > 綜合技術 > 解惑Android的post()方法究竟運行在哪個線程中

解惑Android的post()方法究竟運行在哪個線程中

來源:程序員人生   發(fā)布時間:2016-06-30 13:21:36 閱讀次數(shù):2750次

Android中我們經(jīng)常使用的post()方法大致有兩種情況:

1.如果post方法是handler的,則Runnable履行在handler依附線程中,多是主線程,也多是其他線程

下面是Handler里面的post方法

/** * Causes the Runnable r to be added to the message queue. * The runnable will be run on the thread to which this handler is * attached. * * @param r The Runnable that will be executed. * * @return Returns true if the Runnable was successfully placed in to the * message queue. Returns false on failure, usually because the * looper processing the message queue is exiting. */ public final boolean post(Runnable r){ return sendMessageDelayed(getPostMessage(r), 0); }

2.如果post方法是View的,則1定是運行在主線程中的,由于所有view都自帶1個handler,所有handler都有post方法,所以它的Runnable是運行在主線程中的

下面是View中的post方法

/** * <p>Causes the Runnable to be added to the message queue. * The runnable will be run on the user interface thread.</p> * * @param action The Runnable that will be executed. * * @return Returns true if the Runnable was successfully placed in to the * message queue. Returns false on failure, usually because the * looper processing the message queue is exiting. * * @see #postDelayed * @see #removeCallbacks */ public boolean post(Runnable action) { final AttachInfo attachInfo = mAttachInfo; if (attachInfo != null) { return attachInfo.mHandler.post(action); } // Assume that post will succeed later ViewRootImpl.getRunQueue().post(action); return true; }

例如:Imageview自帶1個handler,它有postDelayed方法,由于imageview是主線程上的,所以Runable是運行在主線程中的代碼。

imageview.postDelayed(new Runnable() { @Override public void run() { Intent mIntent = new Intent(MainActivity.this, SecondActivity.class); startActivity(mIntent); finish(); } }, 2000);
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 国产99在线 | 亚洲 | 国产精品婷婷久久久久 | 精品成人 | 久久看看 | 成人欧美一区二区三区视频xxx | 国产成人精品午夜 | 99久热| 国产一区二区三区免费看 | 亚洲精品在线播放 | 久久久精品一区二区三区 | 毛片久久 | 亚洲天堂影视 | www欧美| 7777视频| 国产精品不卡 | 免费av网站在线观看 | 91欧美一区二区三区成人 | 欧美激情一区二区三区 | 婷久久| 精品成人免费一区二区在线播放 | 精品国产乱码久久久久久丨区2区 | 国产精品一区二区三区四区在线观看 | 九九热精品视频在线播放 | 在线观看av资源 | 天天插天天插 | 成人影院免费观看 | 成人在线免费视频观看 | 91精品国产91久久综合桃花 | 99热国内精品| 中文字幕91av | 久久成年人视频 | 亚洲精品20p | 91看片淫黄大片91桃色 | 成人免费观看在线 | 国产精品免费一区二区三区四区 | 久久久久99 | 激情视频国产 | 国产成人在线不卡 | 国产一区二区精品 | 免费看男女www网站入口在线 | 国产精品无码专区在线观看 |