Android Service两种起动启动方式

Android Service两种启动启动方式

startService:
正常调用:onCreate->onStart
取消绑定:onDestroy
如果调用者自己直接退出而没有调用stopService,则Service会一直在后台运行,直到下次调用者再启动起来,并明确调用stopService

bindService
正常调用:onCreate->onBind
取消绑定:onUnbind->onDestroy

先startService,再bindService
onCreate->onStart->onBind(onCreate只调用一次)
先stopService 再unbindService
点stopService不起作用,点unbindService后,立即输入2条:
onUnbind->onDestroy
如果先unbindService再stopService
则顺序输出:onUnbind->onDestroy

先bindService再startService
onCreate->onBind->onStart(onCreate只调用一次)
先stopService再unbindService
点stopService不起作用,点unbindService后,立即输入2条:
onUnbind->onDestroy
如果先unbindService再stopService
则顺序输出:onUnbind->onDestroy