http://youngcode.diandian.com/post/2012-08-15/40035171452
使用startService启动服务,同时还可以使用bindService绑定服务,但是现在不能再使用stopService暂停服务,只能使用unbindService解除绑定服务(暂停服务)
使用startService的生命周期:点击startService按钮(onCreate——onStartCommand——onStart),再次点击startService按钮(onStartCommand——onStart),说明onCreate只在创建的时候调用一次,点击stopService按钮(onDestory)。
使用bindService绑定服务,注意在退出Activity时,需要在onDestory解除绑定服务,不然会报错。
使用bindService的生命周期:点击bindService按钮(onCreate——onBind),再次点击bindService按钮(没有调用任何方法);点击unBindService按钮(onUnbind——onDestory)。
使用startService启动服务,再使用bindService绑定服务,再点击unbindService解除绑定(或者直接退出当前绑定服务的Activity),服务并不会停止,而是继续运行,需要再次点击stopService才能停止服务。