这几天终于搞清楚local service与thread应用场合的区别。 为了不误导浏览帖子后来者。在此澄清1、local service 与 thread 不是统一级别的概念。 2、一般service的具体操作都是由单独的一个线程处理(典型的是由 HandleThead处理,这样和主线程就可以通过handler.sendmessage 传递数据) 3、启动service后,如果应用中的所有acitvity都推出(按返回键),这时,应用程序还会存在,不过是以service的形式存在。 acitivity随时可能被系统destroy而service不会。 这样local service 就有改变程序生命周期的左右。这就是service的一大作用。另外, remote service 和local service 提供的功能基本一致。 不同在于 remote service 是单独一个进程。要通过ipc 与client传递数据。
================================================================= 1、local service 与 thread 不是统一级别的概念。 这句话没看明白
Thus a Service itself is actually very simple, providing two main features: * A facility for the application to tell the system about something it wants to be doing in the background (even when the user is not directly interacting with the application). This corresponds to calls to Context.startService(), which ask the system to schedule work for the service, to be run until the service or someone else explicitly stop it. * A facility for an application to expose some of its functionality to other applications. This corresponds to calls to Context.bindService(), which allows a long-standing connection to be made to the service in order to interact with it.
希望是这样~ 否则真搞不懂android这么做为了啥...hehe
“比intent更加高效” 是什么意思,不太理解,希望仁兄解释一下:)
一般直接用thread
比较同意 aclongking的看法。
2、一般service的具体操作都是由单独的一个线程处理(典型的是由 HandleThead处理,这样和主线程就可以通过handler.sendmessage 传递数据)
3、启动service后,如果应用中的所有acitvity都推出(按返回键),这时,应用程序还会存在,不过是以service的形式存在。 acitivity随时可能被系统destroy而service不会。 这样local service 就有改变程序生命周期的左右。这就是service的一大作用。另外, remote service 和local service 提供的功能基本一致。 不同在于 remote service 是单独一个进程。要通过ipc 与client传递数据。
=================================================================
1、local service 与 thread 不是统一级别的概念。 这句话没看明白
[email protected]
* A facility for an application to expose some of its functionality to other applications. This corresponds to calls to Context.bindService(), which allows a long-standing connection to be made to the service in order to interact with it.
首先,我知道Thread和service不是一个概念,但是他们有共通点。我的问题就是,在线程方面,Thread和Service那个更好?各自有什么优缺点!?
比如,在一个socket联网的程序中,是用Thread好一些还是用service好一些?