我被以下情况困住了。我的应用程序中有一项服务。该 Activity 使用 startService() 启动它,以防止它在将来解除绑定(bind)时关闭。然后使用 bindService() 绑定(bind)到服务,然后使用 unbindService() 解除绑定(bind)。一切正常且符合预期:调用 onBind/onUnbind 并且服务保持运行。但是当我从这个或另一个 Activity 中再次调用 bindService() 时,我有另一种行为:onBind 和 onRebind 都没有被调用,但 onServiceConnected() 仍然被调用,我得到了在 onBind() 中返回的 IBinder 实现。有任何想法吗?提前谢谢!

最佳答案

onRebind() 只有当 onUnbind(Intent) 的实现被覆盖以返回 true 时才会调用它。

这样做了吗?

10-08 03:17