防止 API10 上的多个并行异步任务?
Prevent multiple parallell AsyncTask's on API10?
根据 the documentation for AsyncTask,它在某些较旧的 API 上使用并行线程池:
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.
如果即使在 pre-Honeycomb 上我真的想要非并行执行怎么办?
在较新的 API 上,它们一个接一个地结束 运行。有什么方法可以在 pre-Honeycomb 上获得相同的行为吗?
简而言之,不,不是 API 本身。它实际上只影响 Donut、Eclair、Froyo 和 Gingerbread。除了使用 AsyncTask
,您还可以使用您自己的线程池执行器和单个线程,以便它序列化事物。但是,在 Honyecomb 之前的版本中,API 本身在框架内是不同的。
根据 the documentation for AsyncTask,它在某些较旧的 API 上使用并行线程池:
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.
如果即使在 pre-Honeycomb 上我真的想要非并行执行怎么办?
在较新的 API 上,它们一个接一个地结束 运行。有什么方法可以在 pre-Honeycomb 上获得相同的行为吗?
简而言之,不,不是 API 本身。它实际上只影响 Donut、Eclair、Froyo 和 Gingerbread。除了使用 AsyncTask
,您还可以使用您自己的线程池执行器和单个线程,以便它序列化事物。但是,在 Honyecomb 之前的版本中,API 本身在框架内是不同的。