首页 > 代码库 > Android项目----AsyncTask异步操作
Android项目----AsyncTask异步操作
public abstract class
AsyncTask
extends Object
java.lang.Object | |
? | android.os.AsyncTask<Params, Progress, Result> |
Class Overview
AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.
AsyncTask is designed to be a helper class around Thread
and Handler
and does not constitute a generic threading framework. AsyncTasks should ideally be used for short operations (a few seconds at the most.) If you need to keep threads running for long periods of time, it is highly recommended you use the various APIs provided by the java.util.concurrent
pacakge such as Executor
, ThreadPoolExecutor
and FutureTask
.
An asynchronous task is defined by a computation that runs on a background thread and whose result is published on the UI thread. An asynchronous task is defined by 3 generic types, called Params
, Progress
and Result
, and 4 steps, called onPreExecute
, doInBackground
, onProgressUpdate
and onPostExecute
.
翻译:
AsyncTask能够适合,简单的用户界面线程。这个类允许执行后台操作,在UI线程上返回操作结果,而无需操纵线程或处理程序。
设计是围绕AsyncTask线程和处理器的一个辅助类,并不构成一个通用的线程框架。asynctasks应用于短作业(最多几秒钟)如果你需要保持线程运行很长一段时间,它是高度推荐你使用不同的包裹如java.util.concurrent执行API提供的,线程池和futuretask。
一个异步任务由计算运行在后台线程上,其结果发表在UI线程上定义。一个异步任务是由3的泛型类型定义,称为参数,过程和结果,和4个步骤,被称为onpreexecute,它的doInBackground,onprogressupdate和onpostexecute。
一篇好博客推荐:http://www.cnblogs.com/devinzhang/archive/2012/02/13/2350070.html