service 2种生命周期

1. startService() 启动service (跨Activity存在)
        onCreate --> onStart() --> (重复调用startService()时) --> onStart()
    stopService() 停止service
        onDestroy()

2. bindService() 启动service (依附于当前Activity)
        onCreate() --> onBind()
    unBindService() 或者 Activity 退出时 onDestroy()

 

 

通常的做法是,结合IBinder, 用startService来启动一个Service,然后在其它的地方,用bindService来绑定,比如做音乐播放器,文件断点下载等。

 

 

 

posted on 2011-10-12 15:12  TroyZ  阅读(252)  评论(0编辑  收藏  举报