新聞中心
在這里總結一下:

創(chuàng)新互聯(lián)建站是由多位在大型網(wǎng)絡公司、廣告設計公司的優(yōu)秀設計人員和策劃人員組成的一個具有豐富經(jīng)驗的團隊,其中包括網(wǎng)站策劃、網(wǎng)頁美工、網(wǎng)站程序員、網(wǎng)頁設計師、平面廣告設計師、網(wǎng)絡營銷人員及形象策劃。承接:網(wǎng)站制作、成都網(wǎng)站制作、網(wǎng)站改版、網(wǎng)頁設計制作、網(wǎng)站建設與維護、網(wǎng)絡推廣、數(shù)據(jù)庫開發(fā),以高性價比制作企業(yè)網(wǎng)站、行業(yè)門戶平臺等全方位的服務。
文檔地址
cancelling a task
A task can be cancelled at any time by invoking cancel(boolean). Invoking this method will cause subsequent calls to isCancelled() to return true. After invoking this method, onCancelled(Object), instead of onPostExecute(Object) will be invoked after doInBackground(Object[]) returns. To ensure that a task is cancelled as quickly as possible, you should always check the return value of isCancelled() periodically from doInBackground(Object[]), if possible (inside a loop for instance.)
這是話意思是
我們可以隨時調用 cancel(boolean)去取消這個加載任務,調用這個方法會間接調用 iscancelled 并且返回true 。
當調用cancel()后,在doInBackground()return后 我們將會調用onCancelled(Object) 不在調用onPostExecute(Object)
為了保證任務更快取消掉,你應該在doInBackground()周期性的檢查iscancelled 去進行判斷。
**注意,我們的oncancel和onPostExecute一樣,都是在UI線程中執(zhí)行。。。所以當我們想要取消之后,有些界面變化 我們可以在oncancel里面改變UI.
關于cancel方法
public final boolean cancel (boolean mayInterruptIfRunning)
Attempts to cancel execution of this task. This attempt will fail if the task has already completed, already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.
某些情況下,我們調用cancel(true)可能就會失效
比如 :task已經(jīng)加載完成,或者 已經(jīng)取消過一次,或者是其他情況
當前題目:關于AsyncTask中的cancel方法
轉載來源:http://m.fisionsoft.com.cn/article/coespho.html


咨詢
建站咨詢
