Android源碼——AsynTask

來源:互聯網
上載者:User

標籤:

AsyncTask<Params, Progress, Result>中三個參數為:Params         輸入資料Progress       過程資料Result           結果資料 工作隊列 LinkedlockingQueue 的特性     線程從空的LinkedlockingQueue中取任務執行,線程會被阻塞;     線程向一個滿的LinkedlockingQueue中新增工作,同樣會被阻塞。 onProgressUpdate 和 onPostExecute執行與介面相關的操作。 InternalHandler:case MESSAGE_POST_RESULT:     result.mTask.finish(result.mData[0]); case MESSAGE_POST_PROGRESS:     result.mTask.onProgressUpdate(result.mData); case MESSAGE_POST_CANCEL:     result.mTask.onCancelled();  非同步任務的建立過程:  執行過程:調用execute方法在執行過程中,會調用內部一個Callable對象的成員函數call來執行一個具體工作任務具體任務的執行在doInBackground中如果非同步任務需要執行與介面相關的操作,需要調用publishProgress,該方法會想想sHandler發送一個 MESSAGE_POST_PROGRESS訊息,交給 onProgressUpdate來處理。FutureTask成員函數done被調用done首先調用AsynTask.get方法擷取當前工作任務的結果資料,並將其封裝為 MESSAGE_POST_RESULT訊息AsynTask.finish方法處理 MESSAGE_POST_RESULT訊息。 

Android源碼——AsynTask

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.