服务或绑定服务? [英] Service or Bound Service?

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

问题描述

我要创建一个连接到Android上的XMPP服务器的应用程序。我想保持,直到用户退出连接。

I'm creating an application that connects to an XMPP server on Android. I want to keep the connection on till the user logs out.

我应该使用常规的服务或绑定服务,以保持在连接?

Should I use a regular Service or a Bound Service to keep the connection on?

任何提示,建议和有用的信息都欢迎。

Any tips, advice and helpful information are welcomed.

推荐答案

我喜欢这样的解释:

入门服务是很容易的简单的双向交互编程   从活动向服务,但是,它们需要更复杂和   特设编程具有扩展双向通话其   客户端。

Started services are easy to program for simple one way interactions from an activity to a service, however, they require more complex and ad hoc programming for extended two-way conversations with their clients.

在另一方面,结合的服务可以是用于更多更好的选择   复杂的双向交互活动和服务之间。对于   例如,它们支持双向通话。

In contrast, bound services may be a better choice for more complex two-way interactions between activities and services. For example, they support two-way conversations.

所以,如你所说,如果你想使用该服务使用绑定服务进行交互。通过启动服务(或服务的意图),你可以做到这一点,只是这需要更复杂的编程。 (由道格拉斯·施密特: https://www.youtube.com/watch?v=cRFw7xaZ_Mg (11'10 '')):

So, as you said, If you want to interact with the service use bound service. With started services (or intent services) you could do it, only it would require more complex programming. (by Douglas Schmidt: https://www.youtube.com/watch?v=cRFw7xaZ_Mg (11'10'')):

下面是帮助我了解(感谢道格)的摘要:

Here is a summary that helped me understand (thanks Doug):

最后,让我也最后一个环节: <一href="http://www.techotopia.com/index.php/An_Overview_of_Android_Started_and_Bound_Services">http://www.techotopia.com/index.php/An_Overview_of_Android_Started_and_Bound_Services

Finally, one last link that helped me also: http://www.techotopia.com/index.php/An_Overview_of_Android_Started_and_Bound_Services

启动服务被其他应用程序组件(如活动,甚至是广播接收器)启动,并有可能在后台无限期地运行,直到该服务被停止,或者由Android运行系统破坏为了释放资源。服务将继续运行,如果启动它的应用程序不再在前台,而且即使在万一最初启动该服务的组件被销毁

Started services are launched by other application components (such as an activity or even a broadcast receiver) and potentially run indefinitely in the background until the service is stopped, or is destroyed by the Android runtime system in order to free up resources. A service will continue to run if the application that started it is no longer in the foreground, and even in the event that the component that originally started the service is destroyed

A 绑定服务相似与不同之处在于一开始的服务一般不会返回结果,或允许与启动它的组件交互一个启动的服务。甲界服务,另一方面,可以使起动部件进行交互,和接收来自该服务的结果。

A bound service is similar to a started service with the exception that a started service does not generally return results or permit interaction with the component that launched it. A bound service, on the other hand, allows the launching component to interact with, and receive results from, the service.

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

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