上篇講到需要調動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了