可訪問(wèn)性(accessibility)
1、Image without contentDescription圖像沒(méi)有內(nèi)容描述
這個(gè)是需要對(duì)圖片進(jìn)行一個(gè)描述,不然會(huì)有警告,一般情況下進(jìn)行統(tǒng)一的標(biāo)識(shí)加入
android:c ontentDescription="@string/abc
正確性(correctness)
2、Attribute unused on older versions 舊版本中未使用的屬性
3、Class is not registered in the manifest 類沒(méi)有在清單中注冊(cè)
沒(méi)有注冊(cè)的activity
4、Duplicate ids across layouts combined with include tags布局中重復(fù)的ids與包含標(biāo)簽相結(jié)合
引用的布局和父布局包含相同的id
5、Implied locale in date format 使用日期格式的默示語(yǔ)言環(huán)境
http://blog.csdn.net/revival_liang/article/details/51812723
時(shí)間聲明問(wèn)題
SimpleDateFormat format = new SimpleDateFormat("MM月dd日HH時(shí)mm分ss秒");//有報(bào)警問(wèn)題 SimpleDateFormat format = new SimpleDateFormat("MM月dd日HH時(shí)mm分ss秒", Locale.getDefault());
6、Incorrect order of elements in manifest 清單中元素的順序不正確
有些權(quán)限需要寫道application之前,示例極光的一個(gè)權(quán)限
<uses-permission android:name="packagename.permission.JPUSH_MESSAGE" />
7、Layout Inflation without a Parent 父布局沒(méi)有膨脹
示例 使用null
View view = inflater.inflate(R.layout.progressbar, null);
正確的使用 第三個(gè)參數(shù)設(shè)置為了true,表示將第一個(gè)參數(shù)所指定的布局添加到第二個(gè)參數(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)用
一般報(bào)錯(cuò)
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(); 改為(暫未測(cè)試效果) 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()
`
這兩個(gè)方法的區(qū)別在于:
- apply沒(méi)有返回值而commit返回boolean表明修改是否提交成功
- apply是將修改數(shù)據(jù)原子提交到內(nèi)存, 而后異步真正提交到硬件磁盤, 而commit是同步的提交到硬件磁盤,因此,在多個(gè)并發(fā)的提交commit的時(shí)候,他們會(huì)等待正在處理的commit保存到磁盤后在操作,從而降低了效率。而apply只是原子的提交到內(nèi)容,后面有調(diào)用apply的函數(shù)的將會(huì)直接覆蓋前面的內(nèi)存數(shù)據(jù),這樣從一定程度上提高了很多效率。
- apply方法不會(huì)提示任何失敗的提示。
由于在一個(gè)進(jìn)程中,sharedPreference是單實(shí)例,一般不會(huì)出現(xiàn)并發(fā)沖突,如果對(duì)提交的結(jié)果不關(guān)心的話,建議使用apply,當(dāng)然需要確保提交成功且有后續(xù)操作的話,還是需要用commit的。
10、Nested scrolling widgets 嵌套滾動(dòng)窗口小部件
scrollview中嵌套了listview
11、Obsolete Gradle Dependency 過(guò)時(shí)Gradle依賴
提示android 升級(jí)高版本
12、RecyclerView Problems recycleerview的問(wèn)題
在onBindviewholder方法中不能使用position 應(yīng)該使用holer.getAdapterPosition()來(lái)獲取position 有時(shí)候在做item換位置時(shí)直接使用postiion會(huì)發(fā)生位置錯(cuò)誤 無(wú)法獲取到變換后的位置
13、ScrollView size validation scrollview大小的驗(yàn)證
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屬性不是針對(duì)最新版本的
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)列表中的最后一個(gè)子應(yīng)該省略一個(gè)狀態(tài)限定符。如果沒(méi)有,則列表中的所有后續(xù)項(xiàng)都將被忽略,因?yàn)榻o定的項(xiàng)將匹配所有項(xiàng)
16、Using deprecated resources 過(guò)時(shí)的方法
17、Using inlined constants on older versions quanxu
Internationalization 國(guó)際化
18、Hardcoded text 硬編碼
https://toutiao.io/posts/572671/app_preview
19、TextView Internationalization
java 代碼中使用的漢字應(yīng)使用常量來(lái)代替(個(gè)人建議)
20、 Bidirectional Text 雙向設(shè)置
如 :
android:paddingLeft="15dp"
需要設(shè)置兩側(cè)對(duì)應(yīng)
android:paddingLeft="15dp" android:paddingRight="15dp"
Performance 性能
21、FrameLayout can be replaced with <merge> tag FrameLayout可以替換為<merge>標(biāo)簽 MergeRootFrame
如果FrameLayout是根布局,并且不提供背景或填充等,它通??梢蕴鎿Q為稍微更有效的<merge>標(biāo)簽。請(qǐng)注意,這取決于上下文,因此請(qǐng)確保在繼續(xù)之前了解<merge>標(biāo)記的工作原理。
22、Handler reference leaks handle引起程序泄露參考
因?yàn)橥粋€(gè)線程下的handler共享一個(gè)looper對(duì)象,消息中保留了對(duì)handler的引用,由于Java在生成內(nèi)部類的時(shí)候,原本沒(méi)有構(gòu)造器的內(nèi)部類會(huì)被生成一個(gè)帶外部類參數(shù)的構(gòu)造器,這個(gè)內(nèi)部類就會(huì)持有外部類的隱式引用。Handler其實(shí)隱式的持有了Activity的引用,只要有消息在隊(duì)列中,那么handler便無(wú)法被回收,如果handler不是static那么使用Handler的Service和Activity就也無(wú)法被回收。這就可能導(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)重屬性的時(shí)候相應(yīng)的寬高屬性應(yīng)設(shè)為0dp
25、Layout hierarchy is too deep 布局層次結(jié)構(gòu)太深
嵌套過(guò)多的布局不利于性能??紤]使用更平的布局(比如相對(duì)布局或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時(shí)它的子控件不對(duì)齊
當(dāng)linearlayout為水平時(shí)設(shè)置為fale 獲取更好的性能
http://blog.csdn.net/bdmh/article/details/48495583
28、Nested layout weights 嵌套布局權(quán)重
避免權(quán)重套權(quán)重,當(dāng)一個(gè)非零權(quán)重的線性布局被嵌套在另一個(gè)帶有非零權(quán)重的線性布局中,那么度量的數(shù)量就會(huì)呈指數(shù)增長(zhǎng)。
29、Node can be replaced by a TextView with compound drawables 節(jié)點(diǎn)可以用一個(gè)帶有復(fù)合繪圖的TextView來(lái)替換
讓只有圖片和文字的一個(gè)小布局合并為一個(gè)textview 這個(gè)視情況。
30、Obsolete layout params 布局中無(wú)用的參數(shù)
31、Overdraw: Painting regions more than once 過(guò)度繪制
一般布局根背景不需要在設(shè)置bg了 子布局的背景擋住的父布局造成了過(guò)度繪制
32、Static Field Leaks 靜態(tài)變量泄露
主要是上下文對(duì)象不要設(shè)置為static