官方解释如下:
Called when new clients have connected to the service, after it had previously been notified that all had disconnected in its onUnbind. This will only be called if the implementation of onUnbind was overridden to return true.
Service中onRebind方法被调用的两个必要条件
(1)服务中onUnBind方法返回值为true
(2)服务对象被解绑后没有被销毁,之后再次被绑定
模拟调用流程:
先启动服务(onCreate, onStartCommand);
03-
08 16:
46:
06.992 24411-
24411/
com.lsw.demo I/MyService: onCreate:
03-
08 16:
46:
07.027 24411-
24411/
com.lsw.demo I/MyService: onStartCommand:
再绑定服务(onBind);
03-
08 16:
46:
10.771 24411-
24411/
com.lsw.demo I/MyService: onBind:
再解除绑定服务(onUnBind)(由于服务被启动过,所以Service中onDestroy不会被调用);
03-
08 16:
56:
45.922 24411-
24411/
com.lsw.demo I/MyService: onUnbind:
再绑定服务;
03-
08 16:
57:
05.040 24411-
24411/
com.lsw.demo I/MyService: onRebind:
这次绑定的服务对象是之前已经创建好的,所以这次绑定服务时就会调用onReBind方法了,并且本次不会调用onBind方法。
相关代码见如下网站: link
转载请注明原文地址: https://ju.6miu.com/read-4185.html