读书人

AsyncTask异步形式详解及其使用

发布时间: 2012-07-16 15:44:59 作者: rapoo

AsyncTask异步方式详解及其使用

查看官方的解释:

?

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.

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,?Progressand?Result, and 4 steps, called?begin,?doInBackground,?processProgress?and?end.

?

Usage:

?

AsyncTask 是abstract class必须被子类继承使用。至少要重写一个方法:(doInBackground(Params...)), 经常还要重写另一个方法:(onPostExecute(Result).)

?

demo:

}
}

?

创建后,使用起来,非常简单:

?

?new DownloadFilesTask().execute(url1, url2, url3);??

?

在网上搜了一下,这篇文章讲解的不错。

http://blog.csdn.net/zuolongsnail/article/details/6394055

?

?

读书人网 >移动开发

热点推荐