IntentService 和 Service 有什么区别? [英] What is the difference between an IntentService and a Service?

查看:36
本文介绍了IntentService 和 Service 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能帮我理解 IntentServiceService 之间的区别是什么吗?

Can you please help me understand what the difference between an IntentService and a Service is?

推荐答案

简而言之,Service 是一种更广泛的实现,供开发人员设置后台操作,而 IntentService 用于即发即忘"操作,注意后台线程创建和清理.

In short, a Service is a broader implementation for the developer to set up background operations, while an IntentService is useful for "fire and forget" operations, taking care of background Thread creation and cleanup.

来自文档:

服务服务是一个应用程序组件,表示应用程序希望在不与用户交互的情况下执行更长时间运行的操作,或者提供供其他应用程序使用的功能.

Service A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.

IntentServiceService 是 IntentService 处理异步请求(表示为 Intent)的按需服务的基类.客户端通过startService(Intent)调用发送请求;服务根据需要启动,依次使用工作线程处理每个 Intent,并在工作用完时自行停止.

IntentService Service is a base class for IntentService Services that handle asynchronous requests (expressed as Intents) on demand. 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.

参考此文档 - http://developer.android.com/reference/android/app/IntentService.html

这篇关于IntentService 和 Service 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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