安排在Android的多任务异步 [英] Schedule multiple async task in android

查看:215
本文介绍了安排在Android的多任务异步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要安排或队列在后台执行多个AsyncTask的。我对HTTP POST请求一个AsyncTask的是在服务运行,同时我作出的AsyncTask的UI线程一多了一个HTTP请求。

I want to schedule or queue to execute Multiple AsyncTask in background. I have a AsyncTask for HTTP post request that is running in Service, At the same time i make a one more HTTP request in UI thread of AsyncTask.

UI线程太长的时间来执行,因为已经有一个线程在运行服务。
如何解决此问题。?

UI thread taking too long time to execute, because already one thread is running in service. How to resolve this problem.?

我需要暂停服务线程,我想先执行UI线程,然后再重新启动服务线程的AsyncTask。

I need to Pause a service thread and I want to execute UI thread first and then restart a service thread again for AsyncTask.

在此先感谢

推荐答案

由于AsyncTasks可以共享一个单独的线程我会尝试通过调用去耦它们:

As AsyncTasks can share a single thread I would try decoupling them by calling:

my_task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,(无效[])NULL);

my_task.execute的((无效[])空)

:<一href=\"http://stackoverflow.com/questions/9119627/android-sdk-asynctask-doinbackground-not-running-subclass\">Android SDK AsyncTask的doInBackground没有运行(子类)

的另一种方式是使用执行人框架和的ThreadPoolExecutor

Another way would be to use Executor framework and ThreadPoolExecutor.

这篇关于安排在Android的多任务异步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆