考虑下面的异步任务:
protected class FetchArticlesAsyncTask extends AsyncTask<Category, Integer, HashMap<String, Object>>
{
private final String TAG = FetchArticlesAsyncTask.class.getSimpleName();
private HashMap<String, Object> data;
Bundle bundle = new Bundle();
protected HashMap<String, Object> doInBackground(Category... categories)
{
HashMap<String, Object> result = new HashMap<String, Object>();
Articles articles = ... // Get sth from HTTP
result.put("articles", articles);
Log.d(TAG, "result = " + result); // Print out sth which is OK
return result;
}
protected void onPostExecute(HashMap<String, Object> result)
{
notifyAsyncTask(FetchArticlesAsyncTask.class, result, this.data);
}
..
在我的来电者中,我有
protected void notifyFetchArticlesAsyncTask(Class<?> c, Object result, Object input)
{
HashMap<String, Object> data = (HashMap<String, Object>) result;
Log.d(TAG, "result = " + result); // result is SOMETIMES empty map? WHY
}
问题只是有时我会得到空地图notifyFetchArticlesAsyncTask
,但结果可以成功打印 doInBackground
。
为什么有时不工作?