使用步骤
1.继承AsyncTask<Params,Progress,Result >, 如果不返回就AsyncTask<Void, Void, Void>
2.
//运行次序
2.1.onPreExecute()———ui线程
2.2.doInBackground(Params...) ——其他线程
//如果里面有调用publishProgress(Progress...)
就调用onProgressUpdate(Progress...)———ui线程
2.3.onPostExecute(Result)———ui线程
3.在ui线程运行AsyncTask.execute(Params...)
4.中途取消任务 ,就调用 AsyncTask.cancel(true)
调用cancel(true)会调用 onCancelled()————ui线程
调用cancel(true)后不会调用onProgressUpdate(Progress...)和onPostExecute(Result)
但不会停止doInBackground(Params...) 要停止就要判断isCancelled()是否为true