我試圖從另一個的AsyncTask的doInBackground()
- 方法啓動的AsyncTask ...開始的AsyncTask其他的AsyncTask doInBackground()
這甚至可能嗎?如果是的話,我怎麼能做到這一點?
以後編輯:
的想法是,我啓動的AsyncTask,將讓我從高音狀態......一切OK,直到這裏......但是,當我遇到一些具體的鳴叫,我需要一些修改它們從我的服務器的信息,在這裏我會再拍網絡運行,因爲我需要等待,直到我從服務器獲取信息,我做的事:
GetContent getContentServiceAsyncTask = new GetContent(context);
try {
tweetText = Uri.decode(getContentServiceAsyncTask.execute(
URL_GET_CONTENT, jsonRequest).get());
} catch (InterruptedException e) {
Log.e(TAG_DEBUG, "InterruptedException: ", e);
} catch (ExecutionException e) {
Log.e(TAG_DEBUG, "ExecutionException: ", e);
}
這是從媒體鏈接開始的AsyncTask開始在doInBackground()方法...
我知道我可以ju st在AsyncTask中添加方法,只需在doInBackground()方法中調用它們,但我需要在其他地方使用它們,我從onPostExecute啓動這些AsyncTasks ...
如果你們認爲有一個簡單解決這個問題,這不會影響我的表現,如果不是,我會製作一些靜態方法,我會在我需要的所有AsyncTasks中調用(但這需要我修改很多我的代碼)
你爲什麼要這麼做? http://developer.android.com/reference/android/os/AsyncTask.html。檢查主題線程規則 – Raghunandan
這是可能的,但如果您嘗試從第二個任務上的onPostExecute修改UI,它將會崩潰,因爲它沒有在主線程中執行。 – Juangcg
如果您的第二項任務不包含UI操作,則可以開始。 – nurisezgin