多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

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

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

來源:程序員人生   發布時間:2016-06-30 13:21:36 閱讀次數:2744次

Android中我們經常使用的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);
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 日本护士xxxx视频免费 | 日本一区二区不卡在线 | 黄色www| 中文字幕乱码一二三四区 | 亚洲国产成人资源在线软件 | 自拍中文字幕 | 国产高清毛片 | 91精品福利观看 | 日韩特黄特色大片免费视频 | 国产95在线 | 亚洲 | 亚洲欧美第一页 | 免费视频网站在线观看 | 久久国产精品久久国产片 | 欧美1069| 国产精品成人免费福利 | 欧美18videossex性欧美 | 亚洲一区二区三区高清 不卡 | 伊人五月在线 | 成人eeuss影院在线观看 | 最近的中文字幕视频完整 | 免费看羞羞动漫视频网站 | 久久黄网| www久| 亚洲成人资源 | 中文字幕第7页 | 欧美天堂视频 | 成人男女网免费 | 国产精品视频在线观看 | 青春草久久 | 欧美最猛黑人xxxx黑人猛交 | 国产婷婷一区二区在线观看 | 大色欧美| 成人无高清96免费 | 久久做 | 国产在线播放成人免费 | 欧美18一19sex性hd| 日本黄色免费片 | 午夜dj视频在线观看免费 | 精彩视频在线观看 | 91亚洲国产成人精品性色 | 国产激情在线观看完整流畅 |