在我的 Android 项目中,我AsyncTask
用于Facebook API
新闻提要请求。我收到错误:OnPostExecute method executed before doInBackground request finish.
private class NewsFeedAsyncTask extends AsyncTask < Integer, Integer, Boolean > {
@Override
protected Boolean doInBackground(Integer...params) {
if (Session.getActiveSession().getState().isOpened()) {
Get_news_feed();
return true;
}
return false;
}
@Override
protected void onPostExecute(Boolean t) {
super.onPostExecute(t);
adapter = new FacebookAdapter(data, context);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
mPullRefreshListView.onRefreshComplete();
}
}
fetchNewsFeed ()
public void fetchNewsFeed() {
Session.openActiveSessionFromCache(context);
if (Session.getActiveSession().getState().isOpened()) {
Request.executeGraphPathRequestAsync(
Session.getActiveSession(), "me/home", new Request.Callback() {
@Override
public void onCompleted(
Response response) {
}
}
}
}
}
OnActivityCreated()
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
new NewsFeedAsyncTask().execute();
}