camelCaseCoder camelCaseCoder - 10 months ago 101
Android Question

Android marshmallow WifiManager leaking IntentReceiver

Here's the scenario, I have a

that makes use of the
to obtain the IP address like this:

WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
String ipAddress = wifiManager.getConnectionInfo().getIpAddress();

I do not register any receiver to receive any WiFi updates. I use the
to obtain the IP Address only and nothing else.

Now when I complete login, I call
and start
and that's when I see the following log in console:

LoginActivity has leaked IntentReceiver
that was originally registered here. Are you missing a call to

And I get this log only on marshmallow. This does not happen on <6.0 devices ever. Also on marshmallow, the app never crashes but I see this log every time.

If anyone can explain this behaviour?

Kai Kai
Answer Source

I had the same error, but only when running in debug for some reason.

Adding: getApplicationContext() fixed the issue for me. (Although I'm not entirely sure why?)

WifiManager wifi_manager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);