我为什么要采用Android的服务,而不是Java线程 [英] why should i use android service instead of java thread

查看:161
本文介绍了我为什么要采用Android的服务,而不是Java线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑与Android服务和Java线程。

I am confused with android services and java thread.

请帮助我了解其中情况下我应该使用他们。

Please help me to understand in which scenario i should use them.

按我的理解

服务在后台运行,这样做的线程。

Service run in background ,so do thread.

服务是要用于如网络操作或播放MP3背景活动,所以做线程。

Service is to be used for activities like network operation or playing mp3 in background,so do threads.

因此​​,whats他们之间的实际差异时使用它们。

So whats actual difference between them and when to use each of them.

推荐答案

让我举一个比喻。

活动和服务都喜欢的项目。

活动,如外部项目。这就是客户端(用户)看到的。

Activities are like external projects. This is what the clients(users) see.

服务就像是内部项目。可能有几个内部项目,1个外部项目或根本没有。

Services are like internal projects. There might be several internal projects for 1 external project or none at all.

您可以暂停外项目,但支持它仍可继续进行内部项目。

You can "pause" external project but the internal project that supports it can still continue.

主线程像老板在一家公司

老板不应该被耽误了太多的工作,因为他不应该迟到会议(UI冻结)或客户端(用户)会不高兴的。

The boss should never be held up by too much work since he shouldn't be late to meetings (UI freezing) or the client(user) will be unhappy.

线程就像一个公司的员工。

您拥有得越多,越多的事情,你可以在同一时间做的前提是你有足够的设备(CPU速度)对所有的人。

The more you have, the more things you can do at the same time provided you have enough equipment(CPU speed) for all of them.

多的员工可以在同一个项目在同一时间工作,但老板要真正在活动上只工作。

Multiple employees can work on the same project at the same time but the boss should really work only on the Activities.

这篇关于我为什么要采用Android的服务,而不是Java线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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