startService和bindService启动:
当service还没启动时,都会调用onCreate方法,如果已经启动了,将不会 调用onCreate
startService调用多次,会调用多次onStartCommad
binService调用多次,会调用bindService多次(指不同的连接)。
由service又被StartService调用过的,service会一直在后台,必须显示的调用stopService才能停止service或者service本身调用stopService。
stopService有个方法是stopService(int startdID)执行的时会将startID会和最新的id对比,如果不相等的话就不会停止服务,防止停止服务的时候又有请求。
当只由bindService启动的app,都所有客户端都调用过unbind之后,系统会调用onDestroy,杀死Service。
如果onBinder返回为空,则serviceConnected不会调用。
Additionally, if your service is started and accepts binding, then when the system calls your onUnbind() method, you can optionally return true if you would like to receive a call to onRebind() the next time a client binds to the service. onRebind() returns void, but the client still receives the IBinder in its onServiceConnected() callback. The following figure illustrates the logic for this kind of lifecycle.