成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

關(guān)于AsyncTask中的cancel方法

移動(dòng)開發(fā) Android
在adroid 應(yīng)用程序中,我們經(jīng)常會(huì)用到異步加載。 所以我們也要知道如何取消加載。 比如,當(dāng)用戶點(diǎn)擊圖片加載時(shí),如果用戶可能需要取消加載。 怎樣取消呢 我去百度找了很久也沒找到 。于是就自己去API文檔中查找。

在這里總結(jié)一下:

文檔地址

 

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.)

這是話意思是

 

我們可以隨時(shí)調(diào)用 cancel(boolean)去取消這個(gè)加載任務(wù),調(diào)用這個(gè)方法會(huì)間接調(diào)用 iscancelled 并且返回true 。

 

當(dāng)調(diào)用cancel()后,在doInBackground()return后 我們將會(huì)調(diào)用onCancelled(Object) 不在調(diào)用onPostExecute(Object)

 

為了保證任務(wù)更快取消掉,你應(yīng)該在doInBackground()周期性的檢查iscancelled 去進(jìn)行判斷。

**注意,我們的oncancel和onPostExecute一樣,都是在UI線程中執(zhí)行。。。所以當(dāng)我們想要取消之后,有些界面變化 我們可以在oncancel里面改變UI.

關(guān)于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.

 

某些情況下,我們調(diào)用cancel(true)可能就會(huì)失效

 

比如 :task已經(jīng)加載完成,或者 已經(jīng)取消過一次,或者是其他情況

責(zé)任編輯:張葉青 來源: eoe Android開發(fā)者社區(qū)
相關(guān)推薦

2010-12-01 14:34:59

AsyncTask異步處理任務(wù)Android

2015-10-23 15:22:16

AsyncTask基礎(chǔ)Android

2011-12-02 14:00:21

JavaOOM

2019-11-07 23:48:12

shell腳本getopts

2014-06-05 15:13:21

BGP

2011-08-08 14:07:49

iPhone開發(fā) 字體

2011-08-15 09:58:25

iPhoneXib文件UITableView

2011-08-16 18:56:11

iPhone開發(fā)Three20

2009-12-03 19:06:01

軟路由設(shè)置

2011-08-19 10:35:19

iPhone應(yīng)用Three20

2012-05-14 10:18:54

jQuery

2020-03-02 00:32:08

Python列表for循環(huán)

2011-08-24 14:47:55

LUA文本編輯器

2009-11-23 12:50:26

ADSL寬帶路由器設(shè)置

2011-06-16 11:01:56

PHP繼承

2012-11-20 12:38:29

2011-08-23 15:57:21

Lua元表元方法

2009-12-08 10:01:12

2009-03-04 10:39:47

面試求職弱點(diǎn)

2012-10-22 16:50:35

IBMdw
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 久久久69| 一区二区三区欧美在线观看 | 亚洲欧美在线观看 | 久久精品国产亚洲夜色av网站 | 激情欧美日韩一区二区 | 天天干天天爱天天操 | 特一级毛片 | 精品国产伦一区二区三区观看说明 | 日韩一二三区 | 久热久热 | 久久久久久久久中文字幕 | 日韩高清不卡 | 中文字幕一区二区三区精彩视频 | 黄色一级大片在线免费看产 | 成人精品在线观看 | 日韩一区二区三区在线视频 | 国产农村妇女精品一区 | 中文字幕av在线 | 中文字幕 国产精品 | 免费一区二区 | 国产伦精品 | 网站黄色在线免费观看 | 亚洲一区二区免费 | 久草资源网站 | 干干干操操操 | 黄色成人在线观看 | 精品在线免费看 | 毛片99 | 久久久蜜桃 | 欧美成人免费电影 | 国产aa | 国产乱肥老妇国产一区二 | 色呦呦网站 | 久久久久国产 | 日韩av免费在线观看 | 影音先锋欧美资源 | 日韩免费福利视频 | www.4hu影院 | 国产成人99久久亚洲综合精品 | 亚洲一区二区三区在线 | 国产精品一区二区久久 |