Android:绑定服务和启动服务之间的差异 [英] Android: Differences between bound and started services

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

问题描述

我正在尝试确定绑定服务和启动服务之间的主要概念(而非实现)差异.这里是要点:

I am trying to identify the main conceptual (not implementation) differences between a bound and started service. Here are the main points:

  1. 绑定服务允许活动与服务之间进行扩展的双向通信,而已启动的服务无需向客户端活动返回任何结果

  1. A bound service allows extended two way communication between the activity and the service whereas a started service need not return any results to the client activity

绑定服务将为多个客户端提供服务(只要至少有一个客户端绑定到该客户端),而启动的服务将执行单个操作,然后关闭.(我知道可以绑定一些启动的服务)

A bound service will service multiple clients (as long as there is at least one client bound to it) while a started service performs a single operation and then shuts down. (I am aware that there can be started services which are also bound)

还有其他主要区别吗?

推荐答案

服务是在后台运行的组件,可以执行长时间运行的操作,而无需与用户进行交互.例如,服务可能会在用户处于其他应用程序中时在后台播放音乐,或者可能会在不阻止用户与活动交互的情况下通过网络获取数据.服务实际上可以采取两种状态:

A service is a component that runs in the background to perform long-running operations without needing to interact with the user. For example, a service might play music in the background while the user is in a different application, or it might fetch data over the network without blocking user interaction with an activity. A service can essentially take two states:

已启动:当应用程序组件(例如活动)通过调用startService()启动服务时,将启动服务.启动后,即使启动该服务的组件被破坏,服务也可以无限期在后台运行.

Started : A service is started when an application component, such as an activity, starts it by calling startService(). Once started, a service can run in the background indefinitely, even if the component that started it is destroyed.

绑定:当应用程序组件通过调用bindService()绑定到服务时,该服务即被绑定.绑定的服务提供了一个客户端-服务器接口,该接口允许组件与该服务进行交互,发送请求,获取结果,甚至跨进程间通信(IPC)进行交互.

Bound : A service is bound when an application component binds to it by calling bindService(). A bound service offers a client-server interface that allows components to interact with the service, send requests, get results, and even do so across processes with interprocess communication (IPC).

这篇关于Android:绑定服务和启动服务之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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