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 studio编译错误二:Error: The WIFI_SERVICE must be looked up on the Application
- Android studio编译错误二:Error: The WIFI_SERVICE must be looked up on the Application
- Android studio编译错误 Error: The WIFI_SERVICE must be looked up on the Application
- 打包时报错: The WIFI_SERVICE must be looked up on the Application context or memory will leak on devic
- The WIFI_SERVICE must be looked up on the Application
- Android Studio 升级到3.0后出现编译错误Error:Cannot choose between the following configurations of project
- 忽略Android资源编译错误 Error: this attribute must be localized
- 如何忽略Android资源编译错误 Error: this attribute must be localized.
- 如何忽略Android资源编译错误 Error: this attribute must be localized.
- 如何忽略Android资源编译错误 Error: this attribute must be localized.
- [android引用他人包出现的错误]All versions of the libraries must be the same at this time.以及It is indirectly re
- 解决编译时出错提示: 'error: array must be initialized with a brace-enclosed initializer' 的错误
- 『Android/Java』Android Studio XML Editor Preview Error:The following classes could not be found
- Android -- setTag的妙用和The key must be an application-specific resource id 异常
- Android studio编译错误 duplicate files during packaging of APK...error
- 关于android sdk foloder can no longer be inside the application folder 这问题在mac版本上android studio的问题
- mysql 安装错误:FATAL ERROR: Neither host '* nor 'localhost' could be looked up with /usr/bin/resolveip
- Xcode编译错误:Synthesized property 'xxxXXX' must either be named the same as a compatible ivar or mus
- Android工程编译错误:The project cannot be built until build path errors are resolved