我有一个简单的异步任务,如下面的片段
protected class DownloadArticlesAsyncTask extends AsyncTask<Category, Integer, HashMap<String, Object>>
{
..
@Override
protected HashMap<String, Object> doInBackground(Category... categories)
{
HashMap<String, Object> result = new HashMap<String, Object>();
List<Article> articles = Util.getArticlesFromServer(categories);
result.put("articles", articles);
Log.d(TAG, "size = " + articles.size()); // Return 1
return result;
}
@Override
protected void onPostExecute(HashMap<String, Object> result)
{
ArrayList<Article> articles = (ArrayList<Article>) result.get("articles");
Log.d(TAG, "size = " + articles.size()); // Return 0, why?
}
}
为什么转移onPostExecute
返回空的大小,它只是有时发生,而不是总是发生。
任何想法?