• 大小: 0.06M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-02-01
  • 标签: Android  异步  

资源简介

Rules::

  • The AsyncTask instance must be created in UI thread. 
  • .execute must be invoked on the UI thread.
  • Never call  objMyTask.onPreExecute(), objMyTask.doInBackground()objMyTask.onProgressUpdate() objMyTask.onPostExecute manually.
  • The AsyncTask can be executed only once (an exception will be thrown if a second execution is attempted.)

AsyncTask have Four Main Method...
  1. onPreExecute() 
  2. doInBackground()
  3. onProgressUpdate()
  4. onPostExecute() 

  • onPreExecute-This method is called first when you start AsyncTask using objAsync.execute().And mostly this method is use for initializing dialog(ProgressDialog,CustomDialog) and showing.
  • doInBackground-The main purpose of AsyncTask is accomplished by this method.Any non-UI thread process is running in this method.Such as Rss Feed Reader,Image and video Uploading and Downloading.You cant handle your View in this method.Because this method is non-UI thread.While any background process is running if you want to handle UI therea are  onProgressUpdate method. after completion of process this method send result to OnPostExecute.
  • onProgressUpdate-While backgrounding task is running ,you can handle your UI using this method .Such as status of downloading or uploading task.and this method is called from  doInBackground.Using publishProgress() you can call onProgressUpdate method to update UI while process is running.
  • onPostExecute -This method is called after the background computation finishes.The result of background process in passed in this method as parameters.And now you can dismiss progress dialog ,to indicate that background task is completed.


You can cancel AsyncTask using objAsyncTask.cancel().then you just check in doInBackground,

if (isCancelled()) {
break;
} else {
       //continue...
}


See this Image For more Clear.


资源截图

代码片段和文件信息

/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package com.samir;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int ic_launcher=0x7f020000;
    }
    public static final class id {
        public static final int btncancel=0x7f050003;
        public static final int btnstart=0x7f050000;
        public static final int progressBar1=0x7f050002;
        public static final int tv1=0x7f050001;
        public static final int tvper=0x7f050004;
    }
    public static final class layout {
        public static final int main=0x7f030000;
        public

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        364  2012-05-29 11:25  Android AsyncTask\.classpath

     文件        853  2012-05-29 11:25  Android AsyncTask\.project

     文件        725  2012-05-29 11:50  Android AsyncTask\AndroidManifest.xml

     目录          0  2012-05-29 12:19  Android AsyncTask\assets

     文件      17430  2012-05-29 12:09  Android AsyncTask\bin\Android AsyncTask.apk

     文件        969  2012-05-29 12:12  Android AsyncTask\bin\classes\com\samir\MainActivity$1.class

     文件       1031  2012-05-29 12:12  Android AsyncTask\bin\classes\com\samir\MainActivity$MyTask$1.class

     文件        920  2012-05-29 12:12  Android AsyncTask\bin\classes\com\samir\MainActivity$MyTask$2.class

     文件       4239  2012-05-29 12:12  Android AsyncTask\bin\classes\com\samir\MainActivity$MyTask.class

     文件       1093  2012-05-29 12:12  Android AsyncTask\bin\classes\com\samir\MainActivity.class

     文件        313  2012-05-29 12:07  Android AsyncTask\bin\classes\com\samir\R$attr.class

     文件        380  2012-05-29 12:07  Android AsyncTask\bin\classes\com\samir\R$drawable.class

     文件        484  2012-05-29 12:07  Android AsyncTask\bin\classes\com\samir\R$id.class

     文件        405  2012-05-29 12:07  Android AsyncTask\bin\classes\com\samir\R$layout.class

     文件        400  2012-05-29 12:07  Android AsyncTask\bin\classes\com\samir\R$string.class

     文件        468  2012-05-29 12:07  Android AsyncTask\bin\classes\com\samir\R.class

     目录          0  2012-05-29 12:19  Android AsyncTask\bin\classes\com\samir

     目录          0  2012-05-29 12:19  Android AsyncTask\bin\classes\com

     目录          0  2012-05-29 12:19  Android AsyncTask\bin\classes

     文件       6836  2012-05-29 12:08  Android AsyncTask\bin\classes.dex

     文件       3966  2012-05-29 11:41  Android AsyncTask\bin\res\drawable-hdpi\ic_launcher.png

     目录          0  2012-05-29 12:19  Android AsyncTask\bin\res\drawable-hdpi

     文件       1537  2012-05-29 11:41  Android AsyncTask\bin\res\drawable-ldpi\ic_launcher.png

     目录          0  2012-05-29 12:19  Android AsyncTask\bin\res\drawable-ldpi

     文件       2200  2012-05-29 11:41  Android AsyncTask\bin\res\drawable-mdpi\ic_launcher.png

     目录          0  2012-05-29 12:19  Android AsyncTask\bin\res\drawable-mdpi

     目录          0  2012-05-29 12:19  Android AsyncTask\bin\res

     文件      11781  2012-05-29 12:09  Android AsyncTask\bin\resources.ap_

     目录          0  2012-05-29 12:19  Android AsyncTask\bin

     文件       1008  2012-05-29 12:07  Android AsyncTask\gen\com\samir\R.java

............此处省略25个文件信息

评论

共有 条评论