可訪問性(accessibility)
1、Image without contentDescription圖像沒有內(nèi)容描述
這個是需要對圖片進行一個描述,不然會有警告,一般情況下進行統(tǒng)一的標(biāo)識加入
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布局中重復(fù)的ids與包含標(biāo)簽相結(jié)合
引用的布局和父布局包含相同的id
5、Implied locale in date format 使用日期格式的默示語言環(huán)境
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 清單中元素的順序不正確
有些權(quán)限需要寫道application之前,示例極光的一個權(quán)限
<uses-permission android:name="packagename.permission.JPUSH_MESSAGE" />
7、Layout Inflation without a Parent 父布局沒有膨脹
示例 使用null
View view = inflater.inflate(R.layout.progressbar, null);
正確的使用 第三個參數(shù)設(shè)置為了true,表示將第一個參數(shù)所指定的布局添加到第二個參數(shù)的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()調(diào)用
一般報錯
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()
`
這兩個方法的區(qū)別在于:
- apply沒有返回值而commit返回boolean表明修改是否提交成功
- apply是將修改數(shù)據(jù)原子提交到內(nèi)存, 而后異步真正提交到硬件磁盤, 而commit是同步的提交到硬件磁盤,因此,在多個并發(fā)的提交commit的時候,他們會等待正在處理的commit保存到磁盤后在操作,從而降低了效率。而apply只是原子的提交到內(nèi)容,后面有調(diào)用apply的函數(shù)的將會直接覆蓋前面的內(nèi)存數(shù)據(jù),這樣從一定程度上提高了很多效率。
- apply方法不會提示任何失敗的提示。
由于在一個進程中,sharedPreference是單實例,一般不會出現(xiàn)并發(fā)沖突,如果對提交的結(jié)果不關(guān)心的話,建議使用apply,當(dāng)然需要確保提交成功且有后續(xù)操作的話,還是需要用commit的。
10、Nested scrolling widgets 嵌套滾動窗口小部件
scrollview中嵌套了listview
11、Obsolete Gradle Dependency 過時Gradle依賴
提示android 升級高版本
12、RecyclerView Problems recycleerview的問題
在onBindviewholder方法中不能使用position 應(yīng)該使用holer.getAdapterPosition()來獲取position 有時候在做item換位置時直接使用postiion會發(fā)生位置錯誤 無法獲取到變換后的位置
13、ScrollView size validation scrollview大小的驗證
ScrollView里的LinearLayout的高度應(yīng)該使用wrap_content
14、Reference to an id that is not in the current layout 引用不在當(dāng)前布局內(nèi)的id
15、Target SDK attribute is not targeting latest version 目標(biāo)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
在選擇器中,只有狀態(tài)列表中的最后一個子應(yīng)該省略一個狀態(tài)限定符。如果沒有,則列表中的所有后續(xù)項都將被忽略,因為給定的項將匹配所有項
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 代碼中使用的漢字應(yīng)使用常量來代替(個人建議)
20、 Bidirectional Text 雙向設(shè)置
如 :
android:paddingLeft="15dp"
需要設(shè)置兩側(cè)對應(yīng)
android:paddingLeft="15dp" android:paddingRight="15dp"
Performance 性能
21、FrameLayout can be replaced with <merge> tag FrameLayout可以替換為<merge>標(biāo)簽 MergeRootFrame
如果FrameLayout是根布局,并且不提供背景或填充等,它通常可以替換為稍微更有效的<merge>標(biāo)簽。請注意,這取決于上下文,因此請確保在繼續(xù)之前了解<merge>標(biāo)記的工作原理。
22、Handler reference leaks handle引起程序泄露參考
因為同一個線程下的handler共享一個looper對象,消息中保留了對handler的引用,由于Java在生成內(nèi)部類的時候,原本沒有構(gòu)造器的內(nèi)部類會被生成一個帶外部類參數(shù)的構(gòu)造器,這個內(nèi)部類就會持有外部類的隱式引用。Handler其實隱式的持有了Activity的引用,只要有消息在隊列中,那么handler便無法被回收,如果handler不是static那么使用Handler的Service和Activity就也無法被回收。這就可能導(dǎo)致內(nèi)存泄露
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 低效的權(quán)重布局
在 設(shè)置權(quán)重屬性的時候相應(yīng)的寬高屬性應(yīng)設(shè)為0dp
25、Layout hierarchy is too deep 布局層次結(jié)構(gòu)太深
嵌套過多的布局不利于性能。考慮使用更平的布局(比如相對布局或GridLayout)。默認(rèn)的最大深度為10,但可以使用環(huán)境變量androidlintmaxdepth配置
26、Memory allocations within drawing code 繪制代碼內(nèi)的內(nèi)存分配
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屬性默認(rèn)為true 這是基準(zhǔn)線設(shè)置,設(shè)置為fale時它的子控件不對齊
當(dāng)linearlayout為水平時設(shè)置為fale 獲取更好的性能
http://blog.csdn.net/bdmh/article/details/48495583
28、Nested layout weights 嵌套布局權(quán)重
避免權(quán)重套權(quán)重,當(dāng)一個非零權(quán)重的線性布局被嵌套在另一個帶有非零權(quán)重的線性布局中,那么度量的數(shù)量就會呈指數(shù)增長。
29、Node can be replaced by a TextView with compound drawables 節(jié)點可以用一個帶有復(fù)合繪圖的TextView來替換
讓只有圖片和文字的一個小布局合并為一個textview 這個視情況。
30、Obsolete layout params 布局中無用的參數(shù)
31、Overdraw: Painting regions more than once 過度繪制
一般布局根背景不需要在設(shè)置bg了 子布局的背景擋住的父布局造成了過度繪制
32、Static Field Leaks 靜態(tài)變量泄露
主要是上下文對象不要設(shè)置為static