登录
首页 » Java » android 异步 执行 任务 例子 附讲解

android 异步 执行 任务 例子 附讲解

于 2013-07-05 发布
0 319
下载积分: 1 下载次数: 0

代码说明:

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... onPreExecute()  doInBackground() onProgressUpdate() 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.

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • phonegap 登录注册实例源码下载(android版)
    登录注册模块代码
    2015-01-19下载
    积分:1
  • android Imageloader 显示网络图片 例子源码
    android Imageloader 显示网络图片 例子源码
    2015-05-29下载
    积分:1
  • android中不错的ExpandableListView实例效果源码
    一、ExpandableListView介绍     一个垂直滚动的显示两个级别(Child,Group)列表项的视图,列表项来自ExpandableListAdapter 。组可以单独展开。   1.重要方法       expandGroup(int groupPos) :在分组列表视图中展开一组,      setSelectedGroup(int groupPosition) :设置选择指定的组。      setSelectedChild(int groupPosition, int childPosition, boolean shouldExpandGroup) :设置选择指定的子项。      getPackedPositionGroup(long packedPosition) :返回所选择的组      getPackedPositionForChild(int groupPosition, int childPosition) :返回所选择的子项      getPackedPositionType(long packedPosition) :返回所选择项的类型(Child,Group)      isGroupExpanded(int groupPosition) :判断此组是否展开  2.代码:ExpandableListContextMenuInfo menuInfo=(ExpandableListContextMenuInfo)item.getMenuInfo();String title=((TextView)menuInfo.targetView).getText().toString();int type=ExpandableListView.getPackedPositionType(menuInfo.packedPosition);if (type==ExpandableListView.PACKED_POSITION_TYPE_CHILD) {int groupPos =ExpandableListView.getPackedPositionGroup(menuInfo.packedPosition);int childPos =ExpandableListView.getPackedPositionChild(menuInfo.packedPosition);二、ExpandableListAdapter    一个接口,将基础数据链接到一个ExpandableListView。此接口的实施将提供访问Child的数据(由组分类),并实例化的Child和Group。 getChildId(int groupPosition, int childPosition) 获取与在给定组给予孩子相关的数据。     getChildrenCount(int groupPosition) 返回在指定Group的Child数目。
    2013-03-07下载
    积分:1
  • android Json解析网络数据并显示 例子
    android Json解析网络数据并显示 例子
    2015-06-15下载
    积分:1
  • android grid 分页示例代码(美团九宫格导航)
       实现美团九宫导航
    2016-06-01下载
    积分:1
  • android 通过wifi传输文件的例子源码,参考茄子快传的原理
    android 通过wifi传输文件的例子源码,参考茄子快传的原理
    2014-08-29下载
    积分:1
  • android 线性布局新手入门例子
    android 线性布局新手入门例子
    2015-03-19下载
    积分:1
  • android txt阅读 例子源码
    android txt阅读 例子源码
    2015-04-06下载
    积分:1
  • java 文件上传示例源码下载
    文件上传
    2015-05-09下载
    积分:1
  • android 音量控制 实例源码,效果不错
    android 音量控制 实例源码,效果不错
    2014-06-03下载
    积分:1
  • 696516资源总数
  • 106914会员总数
  • 0今日下载