可訪問性(accessibility)
1、Image without contentDescription圖像沒有內容描述
這個是需要對圖片進行一個描述,不然會有警告,一般情況下進行統一的標識加入
android:c ontentDescription="@string/abc
正確性(correctness)
2、Attribute unused on older versions 舊版本中未使用的屬性
3、Class is not registered in the manifest 類沒有在清單中注冊
沒有注冊的activity
4、Duplicate ids across layouts combined with include tags布局中重復的ids與包含標簽相結合
引用的布局和父布局包含相同的id
5、Implied locale in date format 使用日期格式的默示語言環境
http://blog.csdn.net/revival_liang/article/details/51812723
時間聲明問題
SimpleDateFormat format = new SimpleDateFormat("MM月dd日HH時mm分ss秒");//有報警問題 SimpleDateFormat format = new SimpleDateFormat("MM月dd日HH時mm分ss秒", Locale.getDefault());
6、Incorrect order of elements in manifest 清單中元素的順序不正確
有些權限需要寫道application之前,示例極光的一個權限
<uses-permission android:name="packagename.permission.JPUSH_MESSAGE" />
7、Layout Inflation without a Parent 父布局沒有膨脹
示例 使用null
View view = inflater.inflate(R.layout.progressbar, null);
正確的使用 第三個參數設置為了true,表示將第一個參數所指定的布局添加到第二個參數的View中
LinearLayout ll = (LinearLayout) findViewById(R.id.ll); LayoutInflater inflater = LayoutInflater.from(this); inflater.inflate(R.layout.linearlayout, ll,true);
8、Missing commit() calls 失蹤的commit()調用
一般報錯
After creating a FragmentTransaction, you typically need to commit it as well
fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.xxxx, new xxxxFragment().newInstance(xxxx),"xxxx"); fragmentTransaction.commit(); 改為(暫未測試效果) fragmentManager.beginTransaction().replace(R.id.xxxx, new xxxxFragment().newInstance(xxxx),"xxxx").commit();
9、Missing commit() on SharedPreference editor
`
SharedPreferences.Editor edit = sp.edit();
edit.putString("isFirstLogin", "0");
edit.commit();
改為 apply()
`
這兩個方法的區別在于:
- apply沒有返回值而commit返回boolean表明修改是否提交成功
- apply是將修改數據原子提交到內存, 而后異步真正提交到硬件磁盤, 而commit是同步的提交到硬件磁盤,因此,在多個并發的提交commit的時候,他們會等待正在處理的commit保存到磁盤后在操作,從而降低了效率。而apply只是原子的提交到內容,后面有調用apply的函數的將會直接覆蓋前面的內存數據,這樣從一定程度上提高了很多效率。
- apply方法不會提示任何失敗的提示。
由于在一個進程中,sharedPreference是單實例,一般不會出現并發沖突,如果對提交的結果不關心的話,建議使用apply,當然需要確保提交成功且有后續操作的話,還是需要用commit的。
10、Nested scrolling widgets 嵌套滾動窗口小部件
scrollview中嵌套了listview
11、Obsolete Gradle Dependency 過時Gradle依賴
提示android 升級高版本
12、RecyclerView Problems recycleerview的問題
在onBindviewholder方法中不能使用position 應該使用holer.getAdapterPosition()來獲取position 有時候在做item換位置時直接使用postiion會發生位置錯誤 無法獲取到變換后的位置
13、ScrollView size validation scrollview大小的驗證
ScrollView里的LinearLayout的高度應該使用wrap_content
14、Reference to an id that is not in the current layout 引用不在當前布局內的id
15、Target SDK attribute is not targeting latest version 目標SDK屬性不是針對最新版本的
15、Unreachable state in a <selector>
In a selector, only the last child in the state list should omit a state qualifier. If not, all subsequent items in the list will be ignored since the given item will match all
在選擇器中,只有狀態列表中的最后一個子應該省略一個狀態限定符。如果沒有,則列表中的所有后續項都將被忽略,因為給定的項將匹配所有項
16、Using deprecated resources 過時的方法
17、Using inlined constants on older versions quanxu
Internationalization 國際化
18、Hardcoded text 硬編碼
https://toutiao.io/posts/572671/app_preview
19、TextView Internationalization
java 代碼中使用的漢字應使用常量來代替(個人建議)
20、 Bidirectional Text 雙向設置
如 :
android:paddingLeft="15dp"
需要設置兩側對應
android:paddingLeft="15dp" android:paddingRight="15dp"
Performance 性能
21、FrameLayout can be replaced with <merge> tag FrameLayout可以替換為<merge>標簽 MergeRootFrame
如果FrameLayout是根布局,并且不提供背景或填充等,它通常可以替換為稍微更有效的<merge>標簽。請注意,這取決于上下文,因此請確保在繼續之前了解<merge>標記的工作原理。
22、Handler reference leaks handle引起程序泄露參考
因為同一個線程下的handler共享一個looper對象,消息中保留了對handler的引用,由于Java在生成內部類的時候,原本沒有構造器的內部類會被生成一個帶外部類參數的構造器,這個內部類就會持有外部類的隱式引用。Handler其實隱式的持有了Activity的引用,只要有消息在隊列中,那么handler便無法被回收,如果handler不是static那么使用Handler的Service和Activity就也無法被回收。這就可能導致內存泄露
http://blog.csdn.net/liangchengfeng/article/details/51999882
23、HashMap can be replaced with SparseArray HashMap可以用SparseArray替換
`
HashMap<Integer, HashMap<String, String>> rightPopCommonList = new HashMap<Integer, HashMap<String, String>>();
改為
HashMap<Integer, HashMap<String, String>> rightPopCommonList = new new HashMap<>();
`
24、Inefficient layout weight 低效的權重布局
在 設置權重屬性的時候相應的寬高屬性應設為0dp
25、Layout hierarchy is too deep 布局層次結構太深
嵌套過多的布局不利于性能。考慮使用更平的布局(比如相對布局或GridLayout)。默認的最大深度為10,但可以使用環境變量androidlintmaxdepth配置
26、Memory allocations within drawing code 繪制代碼內的內存分配
Avoid object allocations during draw/layout operations (preallocate and reuse instead)
You should avoid allocating objects during a drawing or layout operation. These are called frequently, so a smooth UI can be interrupted by garbage collection pauses caused by the object allocations. The way this is generally handled is to allocate the needed objects up front and to reuse them for each drawing operation. Some methods allocate memory on your behalf (such as Bitmap.create), and these should be handled in the same way.
27、Missing baselineAligned attribute 消失的baselineAligned屬性
baselineAligned屬性默認為true 這是基準線設置,設置為fale時它的子控件不對齊
當linearlayout為水平時設置為fale 獲取更好的性能
http://blog.csdn.net/bdmh/article/details/48495583
28、Nested layout weights 嵌套布局權重
避免權重套權重,當一個非零權重的線性布局被嵌套在另一個帶有非零權重的線性布局中,那么度量的數量就會呈指數增長。
29、Node can be replaced by a TextView with compound drawables 節點可以用一個帶有復合繪圖的TextView來替換
讓只有圖片和文字的一個小布局合并為一個textview 這個視情況。
30、Obsolete layout params 布局中無用的參數
31、Overdraw: Painting regions more than once 過度繪制
一般布局根背景不需要在設置bg了 子布局的背景擋住的父布局造成了過度繪制
32、Static Field Leaks 靜態變量泄露
主要是上下文對象不要設置為static