上篇讲到需要调动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了