为什么要在onProgressUpdate重复判断doInBackground中的isCancelled方法?不写好像也没什么大问题
class MyAsyncTask extends AsyncTask<Void,Integer,Void>{ @Override protected Void doInBackground(Void... params) { for (int i = 0; i < 100; i++) { if(mTask.isCancelled()){ break; } try { Thread.sleep(300); } catch (InterruptedException e) { e.printStackTrace(); } publishProgress(i); } return null; } @Override protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); progressBar.setProgress(values[0]); } }