AsyncTask简单入门
关系: java.lang.Object ↳ android.os.AsyncTask<Params, Progress, Result> 概述: AsyncTask是Android提供的轻量级异步类;它在后台线程处理耗时的操作然后可以将处理的结果返回给UI线程处理。由于它不涉及到使用Thread和Handler所以简单易用。 用法: 首先上一段Android Developer的代码: private class DownloadFilesTask extends AsyncTask < URL, Integer, Long > { protected Long doInBackground(URL... urls) { int count = urls.length; long totalSize = 0 ; for ( int i = 0 ; i < count; i ++ ) { totalSize += Downloader.downloadFile(urls[i]); publishProgress(( int ) ((i / ( float ) count) * 100 )); // Escape early if cancel() is called if (isCancelled()) break ; } return totalSize; } protected