我已经开发了一个 Activity,它将解析 JSON 数据并将结果显示在 ListView 中。为此,我正在使用 AsyncTask。
我现在想要的是,当我单击 ListView 中的项目时,文件应该开始下载。我可以在同一 Activity 中编写另一个 AsyncTask 以便此 AsyncTask 为我完成下载工作吗?在同一个 Activity 中有多个 AsyncTasks 有什么问题吗?
最佳答案
根据 Doc是的,你可以。
When first introduced, AsyncTasks were executed serially on a single background thread. Starting with DONUT, this was changed to a pool of threads allowing multiple tasks to operate in parallel. Starting with HONEYCOMB, tasks are executed on a single thread to avoid common application errors caused by parallel execution.
If you truly want parallel execution, you can invoke executeOnExecutor(java.util.concurrent.Executor, Object[]) with THREAD_POOL_EXECUTOR.
最佳答案How本身就在 stackoverflow 上。
关于android - 你能在一个 Activity 中有两个 AsyncTasks 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28936940/