I can create debug apk. But when I try to generate a signed apk, I receive the following message:
Error: The WIFI_SERVICE must be looked up on the Application context or memory will leak on devices < Android N. Try changing to .getApplicationContext() [WifiManagerLeak]
As the error suggests, it seems that WiFiManager
must use the ApplicationContext
, as opposed to the ActivityContext
, otherwise a memory leak can occur. The error was triggered by following code:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
To fix the issue I replaced the above line with:
WifiManager wifi = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
This worked for me
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(getApplicationContext().WIFI_SERVICE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With