首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android Service两种起动启动方式

2012-09-23 
Android Service两种启动启动方式startService:正常调用:onCreate-onStart取消绑定:onDestroy如果调用者

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

热点排行