我想取消特定條件下的異步任務。 我做了以下的東西:AsyncTask進入等待狀態
MyService.java
....
if(condition){
asyncTask.cancel(true); // its return the true as well
}
...
MyAsynTask.java
...
protected Object doInBackground(Object... x) {
while (/* condition */) {
// work...
if (isCancelled()){ // Here task goes in to wait state
break;
}
else{
//continue to download file
}
}
return null;
}
...
使用DDMS我發現,任務進入等待狀態。任何建議來解決這個問題將不勝感激。
謝謝, Yuvi
你不需要檢查它isCancelled()在doInBackground(方法)。只需檢查條件n取消它。 –
任務去?也許線程去? DDMS顯示任務狀態?如果線程進入等待狀態,這是正常的。 – Leonidos
@Leonidos添加屏幕截圖以及... AsyncTask是隻有線程的名稱... – Yuvi