zoukankan      html  css  js  c++  java
  • 启动service和绑定service的区别

    当我们启动service的时候首先会调用 onCreate();然后调用onStartCommand()方法;再次启动service的时候只会调用onStartCommand()方法;因为只有一个服务!

    这时候如果我们返回主界面服务正常运行;

    我们绑定service的时候也会调用 onCreate();但是不会调用onStartCommand();

    如果绑定了service我们返回主界面的时候服务会直接抛出异常,并且执行ondestory方法();

    因为service的启动方式有两种,所以说它的生命周期也有两种,一种是通过启动service,然后执行 onCreate()-->onStartCommand()-->onDestory()

    另外一种是通过绑定service来启动的的时候,生命周期为onCreate()->onBind()->Service running-->onUnbind() -> onDestroy()

    如果由onUnbind()重新执行这个service会调用onRebind()

  • 相关阅读:
    leetcode122
    leetcode121
    leetcode773
    leetcode803
    leetcode658
    leetcode723
    leetcode134
    leetcode340
    leetcode721
    leetcode362
  • 原文地址:https://www.cnblogs.com/84126858jmz/p/4890665.html
Copyright © 2011-2022 走看看