美文网首页
Android Lint 扫描错误记录

Android Lint 扫描错误记录

作者: 陈萍儿Candy | 来源:发表于2020-08-25 16:36 被阅读0次

lint使用参考
https://blog.csdn.net/luzhenyuxfcy/article/details/79398761
lint扫描问题记录及分析
https://blog.csdn.net/wxm1225929690/article/details/53183637
一.warning
1.用SparseIntArray/SparseBooleanArray/LongSparseArray等替代HashMap
2.Set 'android:baselineAligned="false"' on this element for better performance
https://www.jianshu.com/p/07ba80fdd86a
3.Combining 'ellipsize=middle' and 'maxLines=1' can lead to crashes. Use 'singleLine=true' instead.
4.This 'TypedArray' should be recycled after use with '#recycle()'
自定义view时,自定义属性会用到TypedArray,用完需要recycle()
5.Avoid object allocations during draw/layout operations (preallocate and reuse instead)。不要在自定义view的onDraw,onLayout,onMeasure等方法中new对象,消耗性能
6.EditText:'android:password' is deprecated: Use 'inputType' instead
在EditText中要用inputType属性(xml文件中)
7.The WIFI_SERVICE must be looked up on the Application context or memory will leak on devices Android N. Try changing 'context' to 'context.getApplicationContext()',wifi-service生命周期长,context要用Application context,防止内存泄漏
8.Nested weights are bad for performance
LinearLayout嵌套LinearLayout时,两个都用了权重layout_weight,嵌套使用权重效率不高
9.Node can be replaced by a TextView with compound drawables
LinearLayout中一个textview,Imageview,可以用一个Textview加drawable实现
10.Should use valueOf instead of new
不要用new Double("2"),要用Double.valueOf("2");

控件(比如Imageview)不能用static修饰

  1. Overdraw: Painting regions more than once
    Lint扫描,有些activity,fragment,item等出现了overdraw的问题,尝试修改acitvity,activity添加了theme,有theme背景,然而activity的背景和theme的不符合,就在activity的layout的根viewgroup添加了background,出现重绘,造成overdraw。
    修改:AllAnchorActivity. Theme. 改为无背景色,不会overdrawa.
    <style name="NoColorTheme.NoTitleBar" parent="android:Theme.Black.NoTitleBar">
    <item name="android:windowBackground">@null</item>
    </style>

13.This Handler class should be static or leaks might occur (anonymous android.os.Handler)

非静态内部类导致内存泄漏

 private Handler loginHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            .....
        }
    };

相关文章

网友评论

      本文标题:Android Lint 扫描错误记录

      本文链接:https://www.haomeiwen.com/subject/ylnvrktx.html