service中回调函数执行时机
下图中的onStart()改成onStartCommand()
启动/停止service
以下组件A是用来启动service的组件
组件A调用startService(intent)启动service,可以通过intent发送数据给service,service中onStartCommand(Intent intent, int flags, int startId)的参数intent即组件A发送来的intent
组件A调用stopService(intent)来销毁service,此时触发service中onDestroy();
service是单例,且可以被销毁。当多次startService去启动Service,若Service对象存在,就只调用onStartCommand;若Service对象不存在,才会创建Service对象。