Android Service系列(一)三种Service

本篇博客介绍了Android中的三种Service。前台Service会在通知栏显示通知,即便用户不与应用交互也会继续运行;后台Service用户不可感知,API 26及以上版本对其运行有限制,建议用scheduled job替代;Bound Service通过bindService()方法绑定,可实现客户端 - 服务端交互,多个组件可绑定,全部解绑则服务销毁。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

上篇讲到需要调动bindService方法才能实现IPC

本篇开始讲Service

参考:https://developer.android.com/guide/components/services.html

根据上面的链接:一共有三种Service

一 Foreground  前台Service

A foreground service performs some operation that is noticeable to the user. For example, an audio app would use a foreground service to play an audio track. Foreground services must display a Notification. Foreground services continue running even when the user isn't interacting with the app.

翻译要点:前台Service会有一个通知在通知栏

 

二 Background

A background service performs an operation that isn't directly noticed by the user. For example, if an app used a service to compact its storage, that would usually be a background service.

Note: If your app targets API level 26 or higher, the system imposes restrictions on running background services when the app itself isn't in the foreground. In most cases like this, your app should use a scheduled job instead.

翻译要点:后台Service用户不可感知,

note: API26之后 后台Service不给用了,所以要用scheduled job 来替代。

 

三 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, receive results, and even do so across processes with interprocess communication (IPC). A bound service runs only as long as another application component is bound to it. Multiple components can bind to the service at once, but when all of them unbind, the service is destroyed.

翻译要点:

(1)通过bindService()方法绑定 

(2)bound service可以实现客户端-服务端 交互(进程间也行)

(2)可以多个componet绑定一个service,但是如果都解绑了,service就 destroyed了

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值