Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个服务,我使用广播接收器在我的活动和服务之间进行通信。当我通过关闭 wifi 和移动数据来终止我的网络连接时,我的广播接收器不再调用该onReceive()方法。这是正常的吗?有什么解决方法吗?
onReceive()
发生的情况是,当网络连接断开(wifi 或移动数据)时,我的 onStop() 覆盖在启动服务的 Activity 中被调用。在 onStop() 方法中,我正在注销我的广播接收器......所以这就是为什么在我失去网络连接后,我无法再从我的服务与父 Activity 通信。 也许有人可以解释为什么在网络连接丢失时调用 onStop() ......