任何人都可以解释android中的未绑定和绑定服务有什么区别 [英] Can anybody explain what is difference between unbound and bound service in android

查看:229
本文介绍了任何人都可以解释android中的未绑定和绑定服务有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以解释android中的未绑定和绑定服务有什么区别并解释意图服务

Can anybody explain what is difference between unbound and bound service in android and explain about intent service

谢谢

推荐答案

绑定服务

Bound Service

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

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).

当最后一个客户端与服务解除绑定时,系统会销毁 服务 EXCEPT (如果服务是由以下人员启动的) startService

When the last client unbinds from the service, the system destroys the service EXCEPT If the service was started by startService

未绑定服务或已启动

当应用程序组件(例如 活动,通过调用startService()启动它.一旦启动,一项服务 可以无限期地在后台运行,即使 开始它被摧毁.

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.

关于Service类的大多数困惑实际上都是围绕着它不是什么:

Most confusion about the Service class actually revolves around what it is not:

服务不是独立的过程.服务对象本身会 并不意味着它正在自己的进程中运行;除非另有 指定,它与作为其一部分的应用程序在同一进程中运行 的.

A Service is not a separate process. The Service object itself does not imply it is running in its own process; unless otherwise specified, it runs in the same process as the application it is part of.

服务不是线程.它本身并不是一种依靠工作来进行工作的手段. 主线程(以避免应用程序无响应错误).

A Service is not a thread. It is not a means itself to do work off of the main thread (to avoid Application Not Responding errors).

这就是使用 IntentService 的地方.

IntentService 是其子类使用工作线程进行

IntentService is a subclass of Service that uses a worker thread to

处理以下所有启动异步请求(表示为Intent): 需求,一次.客户通过发送请求 startService(Intent)调用;服务根据需要启动,处理 每个Intent依次使用辅助线程,并在其停止时自行停止 用完了.

handle all start asynchronous requests (expressed as Intents) on demand, one at a time. Clients send requests through startService(Intent) calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work.

希望它会有所帮助:)

这篇关于任何人都可以解释android中的未绑定和绑定服务有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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