我有需要運行異步任務作爲內部方法的對象(不在ui線程上),我想將ui線程傳遞給方法,然後在其上實現ui線程這樣的asynctask - 有沒有辦法做到這一點?確保在ui線程上運行異步線程
僞代碼:
public class EditDetails extends Activity{
MyObject obj = new obj;
obj.syncWithServer(EditDetails.this);
}
public class MyObject {
public void syncWithWerver(EditDetails parent){
final class GetUserHttpTask extends AsyncTask<String/* Param */, Boolean /* Progress */, String /* Result */> {
@Override
protected String doInBackground(String... params) {
return "";
}
@Override
protected String onPostExecute(String result) {
//this doesn't run
}
}
}
}
注:目前這是行不通的,因爲onPostExecute是不是doInBackground
編輯
這個代碼後進行燒製的僞代碼實際的問題仍然在發生,我已經列出http://pastebin.com/jW6JpUbghere ..基本上它在pastebin上運行72行之後卡住永不停止onPostExecute
你應該像Boris提到的那樣改變'onPostExecute'方法的返回類型並且嘗試上面的代碼片段。它應該工作。 – 2013-04-22 11:48:41
我已經添加了這個片段 - 我一直無法獲得onPostExecute運行,但結果發生在doInBackground中,所以沒關係我在那裏用結果響應中的「ok」代碼手動運行它 – user2083181 2013-04-22 13:08:05