在AsyncTask中,有三個常用的方法onPreExecute(), onPostExecute(String result), doInBackground(Void... params);
其中onPreExecute()做的是執行任務前的一些初始化操作,包括dialog的初始化等。
onPostExecute(String result)做的是異步任務執行完之後的一些操作,比如dialog的dismiss等操作,其中doInBackground(Void... params)方法執行完之後的返回值作爲參數result。
doInBackground(Void... params)方法中執行的就是異步任務需要完成的事情,比如耗時操作(網絡請求等)。
值得注意的是,onPreExecute()方法和onPostExecute(String result)方法都還是在UI主線程中執行,所以在這兩個方法中,也可以繼續開啓異步任務。doInBackground(Void... params)方法內則是不可以的。