gpt4 book ai didi

java - 无法从另一个 ASyncTask 调用 ASyncTask

转载 作者:行者123 更新时间:2023-12-02 05:04:50 28 4
gpt4 key购买 nike

我查看了其他问题,但未能澄清我对从另一个任务调用任务的疑问,我有以下代码:

protected List<Plan> doInBackground(String... params) 
try {
JSONParsePlans parseJSON = new JSONParsePlans();
return parseJSON.execute(params[0], params[1], params[2]).get();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
} catch (ExecutionExeption e) {
e.printStackTrace();
return null;
}
}

parseJSON 是一个任务,当我运行程序时什么也不做,甚至没有调用任务,这就像 Android 为了安全而省略的一样。

最佳答案

根据这个StackOverflow Post :

but only inside onProgressUpdate() or onPostExecute() since these methods runs on the UI thread. Therefore, start the second AsyncTask on the UI thread by choosing one of the two methods listed above.

因此,您可以从另一个 AsyncTask 调用 AsyncTask,只要它在这两种方法中的任何一个中运行即可。

还有另一篇 StackOverflow 帖子解决了这个问题 here

关于java - 无法从另一个 ASyncTask 调用 ASyncTask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27883142/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com