网络监听只有第一次生效可能是由于以下原因:可能在切换前后台去设置网络情况再回到 app 时,没有正确处理网络状态变化的监听逻辑。可能是监听的注册和注销没有在合适的生命周期方法中进行管理。onWindowStageDestroy() { // Main window is destroyed, release UI related resources hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); } onForeground() { // Ability has brought to foreground hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); this.connTest(); } onBackground() { // Ability has back to background hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); }
网络监听只有第一次生效可能是由于以下原因:
可能在切换前后台去设置网络情况再回到 app 时,没有正确处理网络状态变化的监听逻辑。
可能是监听的注册和注销没有在合适的生命周期方法中进行管理。