从服务机器人执行异步任务 [英] executing asynchronous task from service in android

查看:157
本文介绍了从服务机器人执行异步任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个深化发展的应用和我遇到了一个问题。
我试图运行从服务异步任务,并没有奏效。它说,code是不可达。现在我knwo,无论在后台运行,但我真的想一个服务控制多个asyncronous任务。我该怎么办呢?
我一定要使用线程?
我读过这篇文章,我真的想使用asyncronous任务:
<一href=\"http://stackoverflow.com/questions/3264383/difference-between-service-async-task-thread\">Difference服务,异步任务与放大器之间;线程?

I was developping an application and I ran into a problem. I was trying to run an asynchronous task from a service and it didn't work. It says that the code is unreachable. Now I knwo that both run in Background, but I really want one service to control several asyncronous tasks. how can I do that? Do I have to use threads? I've read this post and I really want to use the asyncronous task: Difference between Service, Async Task & Thread?

此外,是否有可能从另一个执行异步任务?

Also, is it possible to execute an asynchronous task from another one?

感谢您

推荐答案

的AsyncTask 始终工作在主/ UI线程。如果你的服务根据不同的进程正在运行,,然后它不关联到主线程,这就是为什么你不能使用 AsyncTask的服务

AsyncTask always works on main/UI thread. And if your Service is running under a different process then it is not associated to main thread, that's why you cant use AsyncTask in Service.

在你的情况,你是鼓励使用 HandlerThread 尺蠖处理程序在独立线程中执行繁重的任务。

In your case, you are encouraged to use HandlerThread, Looper and Handler to perform heavy lifting on separate thread.

这个文章。

这篇关于从服务机器人执行异步任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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