一、正常情况生命周期
(1)单独使用startService():
onCreate()->onStartCommand()->Service running->调用stopService() 或()->onDestroy()->Service shut down
(2)单独使用bindService():
onCreate()->onBind()->Clients are bound to service->onUnbind()->onDestroy()->Service shut down
二、共同使用情况
(1)startService->bindService 或者 bindService ->startService,顺序无所谓(只影响onBind()和onStartCommand()的先后执行顺序)
(2)两者启动的是同一个service
例子一:按顺序执行
(1)startService:调用onCreate()->onStartCommand()
(2)bindService:调用onBind()
(3)stopService:此时没有调用onDestory() Service仍然在运行!
(4)unbindService:调用onUnbind()->调用了onDestory() 此时Service关闭!
例子二:将例子一3,4调换
(1)startServic:调用onCreate()->onStartCommand()
(2)bindService:调用onBind()
(3)unbindService:调用onUnbind() Service仍然在运行!
(4)stopService:调用onDestory() 此时Service才关闭!
结论:只要还有一种启动方法存在,Service就会继续存活。如果要完全退出Service,那么就得执行unbindService()以及stopService(或stopSelf)