當前位置:商標查詢大全網 - 遊戲電競 - 啟動後的service如何停止

啟動後的service如何停止

在討論如何停止service之前,我們需要回顧壹下啟動service的兩種方式。

生命周期:onCreate()->onStartCommand()->Service running->onDestroy()

生命周期:onCreate()->onBind()->Clients are bound to service->onUnbind()->onDestroy()

(1)startServic:調用onCreate()->onStartCommand()

(2)stopService:調用onDestory()

(1)bindservice:調用onCreate()->onBind()

(2)unbindService:調用onUnbind()->onDestroy()

(1)startServic:調用onCreate()->onStartCommand()

(2)bindService:調用onBind()

(3)stopService:沒有調用onDestory() Service仍然在運行!

(4)unbindService:調用onUnbind()->onDestory() 此時Service關閉!

(1)startServic:調用onCreate()->onStartCommand()

(2)bindService:調用onBind()

(3)unbindService:調用onUnbind() Service仍然在運行!

(4)stopService:調用onDestory() 此時Service才關閉!