您的位置:首页 > 移动开发

Android studio编译错误二:Error: The WIFI_SERVICE must be looked up on the Application

2017-07-17 16:40 591 查看

编译错误

Error: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]


原因

Android 7.0 在获取 WifiManager的时候需要使用.getApplicationContext(),如果未使用会造成内存泄露。

解决方法

原来的:

WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE);


修改为:

WifiManager wifiManager = (WifiManager)getApplicationContext().getSystemService(WIFI_SERVICE);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android
相关文章推荐