Android:AsyncTask 随记

来源:互联网 发布:怎么禁止mac休眠 编辑:程序博客网 时间:2024/05/19 14:51
AsyncTask:是一个abstract类
线程池管理(会根据手机cup的核数来产生最大的线程数)+Handler+回调的方法
5个方法:
onPreExecute:启动一个线程前
英文解释
Runs on the UI thread before {@link #doInBackground}.
doInBackground:线程执行的时候调用
英文解释 
on a background thread
onPostExecute:线程执行后回到UI线程:调用一个方法
Runs on the UI thread after {@link #doInBackground}
publishProgress:在非UI线程里发布
onProgressUpdate:在UI线程里接收

启动一个线程前:回调一个方法onPreExecute:线程执行的时候:调用   Result doInBackground(Params... params):on a background thread线程执行后回到UI线程:调用一个方法 protected void onPostExecute(Result result):Runs on the UI thread after {@link #doInBackground}进度条:publishProgress(Progress... values):
新的线程里面:This method can be invoked from {@link #doInBackground} to publish updates on the UI thread     onProgressUpdate(Progress... values):Runs on the UI thread after {@link #publishProgress} is invoked.     

0 0
原创粉丝点击