zoukankan      html  css  js  c++  java
  • Service工作过程

    Service两种工作状态的作用

    1)启动状态:用于执行后台计算

    2)绑定状态:用于其他组件和Service的交互

    注意:Service这两种状态可以共存,即Service既可以处于启动状态也可以同时处于绑定状态

    Service启动过程

    ContextWrapper.startService-->

    ContextImpl.startService-->

    ContextImpl.startServiceCommon-->

    ActivityManagerNative.getDefault().startService-->

    ActivityManagerService.startService-->

    ActiveServices.startServiceLocked-->

    ActiveServices.startServiceInnerLocked-->

    ActiveServices.bringUpServiceLocked-->

    ActiveServices.realStartServiceLocked-->

    ApplicationThread.scheduleCreateService-->

    (Handler)H.handleMessage-->

    ActivityThread.handleCreateService-->

    ActivityThread.handleServiceArgs-->

    Service.onStartCommand

    handleCreateService主要完成几件事:

    1)通过类加载器创建Service的实例

    2)创建Application对象并调用其onCreate,当然Application的创建过程只会有一次

    3)创建ContextImpl对象并通过Service的attach方法建立二者之间的关系,这个过程和Activity实际上是类似的,毕竟Service和Activity都是一个Context

    4)调用Service的onCreate方法并将Service对象存储到ActivityThread中的一个列表中

    Service绑定过程

    ContextWrapper.bindService-->

    ContextImpl.bindService-->

    ContextImpl.bindServiceCommon-->

    ActivityManagerService.bindService-->

    ActiveServices.bindServiceLocked-->

    ActivityManagerService.bringUpServiceLocked-->

    ActivityManagerService.realStartServiceLocked-->

    ApplicationThread.scheduleBindService-->

    ActiveServices.requestServiceBindingLocked-->

    ActivityThread.handleBindService-->

    ServiceConnection.onServiceConnected-->

    ActivityManagerNative.getDefault().publishService-->

    ActivityManagerService.publishService-->

    ActiveServices.publishServiceLocked-->

    ServiceDispatcher.InnerConnection.connected()-->

    ServiceDispatcher.connected()-->

    RunConnection.run-->

    ServiceDispatcher.doConnected-->

    ServiceConnection.onServiceConnected

    No1:

    ServiceDispatcher起着连接ServiceConnection和InnerConnection的作用

    No2:

    bindServiceCommon主要完成两件事:

    1)将客户端的ServiceConnection对象转化为ServiceDispatcher.InnerConnection对象

    2)接着通过AMS来完成Service的具体的绑定过程,这对应于AMS的bindService方法

  • 相关阅读:
    删除文件夹右键下的部分目录
    c# datagridview导出到excel【转载】
    使用AO新增记录的3种方法【转载】
    AE 打包
    ArcMap 9使用技巧
    ArcEngine 渲染的使用【转载】
    关于数据库版本压缩
    SDE数据源直连
    ArcCatalog 9中的使用技巧
    AE指定字段转成注记
  • 原文地址:https://www.cnblogs.com/anni-qianqian/p/8297836.html
Copyright © 2011-2022 走看看