2014-03-27 96 views
0

在可能在AsyncTask中運行的方法中調用異步任務的正確方法是什麼?Android - 在AsyncTask中運行異步任務

文檔指出的AsyncTask​​方法必須建立在UI線程中運行,所以我不能只是運行另一個AsyncTaskAsyncTask ...

+0

onPreExecute(),onPostExecute(結果結果)上UI線程運行運行。因此,您可以在運行當前任務之後或之前繼續調用另一個AsyncTask。就像[this](http://stackoverflow.com/questions/16146825/run-another-asynctask-in-onpostexecute)。或者您可以嘗試在doInBackground()內使用「runOnUiThread」來打包調用。 – Maruku

回答

0

所有這些都將做到: *從onPostExecute(), onPreExecute()運行其上運行UI線程。 *從doInBackground()用下面的代碼

runOnUiThread { 
@Override 
    public void run() { 
    // ... your code here. 
}