AsyncTask的:哪里doInBackground的返回值()去? [英] AsyncTask: where does the return value of doInBackground() go?
问题描述
致电时的AsyncTask<整数,整数,布尔>
,其中是的返回值:
When calling AsyncTask<Integer,Integer,Boolean>
, where is the return value of:
保护布尔doInBackground(整数... PARAMS)
?
通常我们先从 AsyncTask的新AsyncTaskClassName()执行(参数1,参数2 ......);
,但它似乎并没有返回值。
Usually we start AsyncTask with new AsyncTaskClassName().execute(param1,param2......);
but it doesn't appear to return a value.
在哪里可以的返回值doInBackground()
找到?
推荐答案
该值是那么<一个可用href=\"http://developer.android.com/intl/zh-TW/reference/android/os/AsyncTask.html#onPostExecute%28Result%29\">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的返回值()去?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!