服务的生命周期
服务生命周期具有以下回调
onCreate():
首次创建服务时执行,以便设置你可能需要的初始配置。仅当服务尚未运行时才执行此方法。
onStartCommand():
每次 startService() 由另一个组件(如 Activity 或 BroadcastReceiver)调用时执行。当你使用此方法时,服务将一直运行,直到你调用 stopSelf() 或 stopService()。请注意,无论你调用 onStartCommand() 多少次,都必须调用 stopSelf() 和 stopService() 方法一次才能停止服务。
onBind():
当组件调用 bindService() 并返回 IBInder 实例时执行,为服务提供通信通道。只要有绑定的客户端,对 bindService() 的调用将使服务保持运行。
onDestroy():
在服务不再使用时执行,并允许处理已分配的资源。
值得注意的是,在服务的生命周期中,可能会调用其他回调,例如 onConfigurationChanged() 和 onLowMemory()
https://developer.android.com/guide/components/services.html
