多IntentService或者一个服务 [英] Multiple IntentService or one Service

查看:189
本文介绍了多IntentService或者一个服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IntentService和服务之间的区别有点困惑。据我所知,IntentService有一个工作队列,但没有任何好处使用多个IntentService超过服务?

I'm a little confused on the difference between IntentService and Service. I understand that IntentService has a worker queue, but is there any benefit to using multiple IntentService over one Service?

下面是我的意思的例子。比方说,我希望我的应用程序从3源获取数据。我应该开始运行三个线程每个人从各自的源拉着一个服务?或者我应该开始三个独立的IntentServices?

Here's an example of what I mean. Let's say I want my application to pull data from 3 sources. Should I start a service that runs three threads, each one pulling from their respective source? Or should I start three separate IntentServices?

推荐答案

IntentService仅仅是一个方便的类来编写服务,这是工人在生产 - 消费模式。他们的目的是在连续执行各种任务,然后停止服务。服务不一定IntentServices等服务,必须活下去,如守护进程。

IntentService is just a convenient class to write services that are workers in the producer-consumer pattern. They are services designed to execute various tasks in a row and then stop. Services are not necessarily IntentServices such as services that must stay alive such as daemons.

所以,你应该不知道你的服务是接近辅助线程,如果是的话,使用IntentServices其他人只是从服务中获得。

So you should wonder if you service is close to a worker thread, if so, use IntentServices else just derive from Service.

你的第二个问题是,是否要组1服务的所有3服务3。答案是,这取决于你如何使用你的数据源:如果完全使用它们,然后将它们分组在一个单一的服务。如果它们被分开使用,你可以建立每一个,希望提供一个打火机服务的服务,如果只有一个数据源使用,而不是其他。但是如果你使用的所有3的数据源,在每一个服务,那么这将是比使用单一服务较重。

Your second questions was whether to group all 3 services in a 3 in 1 service. The answer is that it depends how you use your datasources : if you use them altogether, then group them in a single service. If they are used separately, you could build a service for each with the hope to provide a lighter service if only one datasource is used and not the other. But if you use all 3 datasources, each in a service, then it will be heavier than using a single service.

这篇关于多IntentService或者一个服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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