在我的android項目中,我使用AsyncTask來調用Facebook新聞提要的請求。OnPostExecute在doInBackground完成之前運行-AsyncTask
我有AsyncTask問題:在doInBackground請求完成之前執行的OnPostExecute方法。
這裏是我的代碼:
private class Task extends AsyncTask<Integer,Integer, Boolean>{
@Override
protected Boolean doInBackground(Integer... params) {
try {
if(Session.getActiveSession().getState().isOpened()){
Get_news_feed();
return true;
}
return false;
}
catch (NullPointerException e) {
return false;
}
}
@Override
protected void onPostExecute(Boolean t) {
super.onPostExecute(t);
adapter =new Facebook_adapter(facebook.json.gen.klase.Obavijest.data,context);
actualListView.setAdapter(adapter);
adapter.notifyDataSetChanged();
mPullRefreshListView.onRefreshComplete();
}
}
Get_news_feed()
public void Get_news_feed() {
try {
Session.openActiveSessionFromCache(context);
if (Session.getActiveSession().getState().isOpened()) {
context.runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Request.executeGraphPathRequestAsync(
Session.getActiveSession(), "me/home",new Request.Callback() {
@Override
public void onCompleted(
Response response) {
if (response.getGraphObject()!=null){
System.out.println("Json:"+response.getGraphObject().getInnerJSONObject());
});
}
});
}
} catch (Exception e2) {
System.out.println("Error:"+e2);
}
}
}
OnActivityCreated()
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
new Task().execute();
}
什麼是OnBackground方法? – fiddler
對不起,我的意思是doInBackground() –
是什麼讓你覺得'onPostExecute'在'doInBackground'之前被調用? – fiddler