本文介绍了AsyncTask的:doInBackground在哪里返回值()去?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个AsyncTask的

in a AsyncTask

在那里去的返回值保护布尔doInBackground(整数... PARAMS)

通常我们开始AsyncTask的使用新AsyncTaskClassName()执行(参数1,参数2 ......); 不返回任何值

usually we start AsyncTask withnew AsyncTaskClassName().execute(param1,param2......);which doesn't return any value

推荐答案

该值就可以在onPostExecute您可能希望以致使工作覆盖。

The value is then available in onPostExecute which you may want to override in order to work with the result.

下面是来自谷歌的文档例如code片断:

Here is example code snippet from Google's docs:

 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));
          }
          return totalSize;
      }

      protected void onProgressUpdate(Integer... progress) {
          setProgressPercent(progress[0]);
      }

      protected void onPostExecute(Long result) {
          showDialog("Downloaded " + result + " bytes");
      }
 }

这篇关于AsyncTask的:doInBackground在哪里返回值()去?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 13:12