Android四大组件之Service
Service启动过程
1. 相关简介
ActiveServices: 管理所有services
启动过程通过context->AMS->ActiveServices实现
通过ActivityThread的applicationThread实现
process的回调
activityThread中的token为AMS中ProcessRecord的远端
activityThread中有mServices存放了该进程下的所有service,以toke binder作为key,该token为AMS对应的ServiceRecord
2. 流程
Service绑定过程
1. 相关简介
ServiceRecord: 描述一个正在运行的service,其中bindings描述目前绑在该service的intent集合
connections存放所有的service connection
ServiceRecord包含:
- 一个IntentBindRecord的list,每个IntentBindRecord中存放了一个intent和对应的service的binder,以及以这个intent绑定的AppBindRecord的list
- 一个ConnectionRecord的hashmap,该hashmap以ServiceConnection的binder对象为key,存放了以改binder绑定的CR对象。一个CR对象内部有一个AppBindRecord,activity以及ConnectionService对象(封装成了ServiceDispatcher)。
IntentBindRecord: intent和service和app的绑定关系,存放了intent和service的对应关系,以及绑定在该service上的所有app和process
AppBindRecord: 描述service和client的绑定关系,存放在IntentBindRecord
ConnectionRecord: 描述一个service的绑定,包含activity信息等等。描述AppBindRecord到ServiceRecord的绑定关系。即使相同的AppBindRecord(app与service的一个绑定),activity不同也算两个ConnectionRecord,考虑到同一个ServiceConnection可能被不同的activity共用
2. 流程