startService stopService bindService unbindService各种点击情况汇总

各种点击情况

前提:

mainactivity.java

   private ServiceConnection connection = new ServiceConnection() { 

 

       @Override 

       public void onServiceDisconnected(ComponentName name) { 

       } 

 

       @Override 

       public void onServiceConnected(ComponentName name, IBinder service){ 

           myBinder = (MyService.MyBinder) service; 

           myBinder.startDownload(); 

       } 

   };

 

bindService(bindIntent, connection, BIND_AUTO_CREATE);  

 

 

0.1start stop

start : onCreate()  onStartCommand()

stop: onDestroy

 

0.2bind unbind

bind: 服务的 onCreate()    客户端的onServiceConnected()

unbind: onDestroy

 

1.点击两次start

第一次onCreate()  onStartCommand()

第二次onStartCommand()

 

2.点击一次start 一次bind

点start : onCreate()  onStartCommand()

点bind: 调用onServiceConnected,返回服务端的binder

 

3.点一次bind, 再点start

bind: 服务的 onCreate()    客户端的onServiceConnected()

start: 服务的onStartCommand()

 

4.start unbind(unbind只有在已经bind的情况下, 仅仅调用一次)

start: onCreate()  onStartCommand()

unbind:崩溃

 

5.bind stop

bind: 服务的 onCreate()  客户端的onServiceConnected()

stop: 无反应

 

6. start bind stop

start : onCreate()  onStartCommand()

bind: 调用onServiceConnected,返回服务端的binder

stop: 无反应

 

7. start bind unbind/stop

start : onCreate()  onStartCommand()

bind: 调用onServiceConnected,返回服务端的binder

unbind/stop: 无反应

 

8. start bind unbind stop/ start bind stop unbind

start : onCreate()  onStartCommand()

bind: 调用onServiceConnected,返回服务端的binder

stop unbind/ unbind stop: onDestroy

你可能感兴趣的:(android基础)