"缺少调用unregisterReceiver" wifiManager中的错误

时间:2017-07-11 09:07:11

标签: android android-intent broadcastreceiver wifimanager

我没有使用接收器,所以我没有注册或取消注册但是当我多次调用wifiManger方法时,发生了一些错误。 这是我的代码:

   WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
    wifiManager.setWifiEnabled(true);
    int res = wifiManager.addNetwork(wc);
    Log.d("WifiPreference", "add Network returned " + res);
    boolean es = wifiManager.saveConfiguration();
    Log.d("WifiPreference", "saveConfiguration returned " + es);
    if (res != -1 && isEdit) {
        wifiManager.removeNetwork(configEdit.networkId);
        wifiManager.saveConfiguration();
        isEdit = false;
    }

非常感谢大家的帮助

错误日志:

泄露了最初在这里注册的IntentReceiver android.net.wifi.WifiManager$1@a517b6e。您是否错过了对unregisterReceiver()

的调用

1 个答案:

答案 0 :(得分:0)

更改

WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);

WifiManager wifiManager = (WifiManager) getApplicationContext.getSystemService(WIFI_SERVICE);

你这样做可能会泄漏内存