Android開發(fā)中那些需要注意的坑
這個是看知乎的時候發(fā)現(xiàn)的一個問題,感覺挺有意思,就將自己遇到的坑記錄下來。
1、Andorid L theme colorPrimary 不能使用帶有alpha的顏色值,否則會有異常拋出, 直接判斷了是否alpha是否等于0或者255,其他都會異常
@Override
protected void onApplyThemeResource(Resources.Theme theme, int resid,
boolean first) {
if (mParent == null) {
super.onApplyThemeResource(theme, resid, first);
} else {
try {
theme.setTo(mParent.getTheme());
} catch (Exception e) {
// Empty
}
theme.applyStyle(resid, false);
}
// Get the primary color and update the TaskDescription for this activity
if (theme != null) {
TypedArray a = theme.obtainStyledAttributes(com.android.internal.R.styleable.Theme);
int colorPrimary = a.getColor(com.android.internal.R.styleable.Theme_colorPrimary, 0);
a.recycle();
if (colorPrimary != 0) {
ActivityManager.TaskDescription v = new ActivityManager.TaskDescription(null, null,
colorPrimary);
setTaskDescription(v);
}
}
}
/**
* Creates the TaskDescription to the specified values.
*
* @param label A label and description of the current state of this task.
* @param icon An icon that represents the current state of this task.
* @param colorPrimary A color to override the theme's primary color. This color must be opaque.
*/
public TaskDescription(String label, Bitmap icon, int colorPrimary) {
if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
throw new RuntimeException("A TaskDescription's primary color should be opaque");
}
mLabel = label;
mIcon = icon;
mColorPrimary = colorPrimary;
}
2、android 5.0花屏,由于過度繪制導(dǎo)致,關(guān)閉硬件加速, 尤其是使用webview后,可能會有大概率出現(xiàn)。
3、華為手機(jī)被KILL一系列問題
用戶可以設(shè)置某個應(yīng)用是否后臺保護(hù),按照華為的功能說明,理解為,如果不保護(hù),那鎖屏后程序?qū)o法保持運行,也就是進(jìn)程可能被KILL
新安裝應(yīng)用后,華為會給出選項,是否保持,這個默認(rèn)選項上存在問題,有的應(yīng)用默認(rèn)不允許,有的應(yīng)用默認(rèn)就允許。
關(guān)于耗電高被KILL問題。
關(guān)于鎖屏后網(wǎng)絡(luò)被切斷問題。鎖屏就算保護(hù),而網(wǎng)絡(luò)或者SOCKET也可能被主動切斷。
華為自己給出了BASTET系統(tǒng)解決方案,具體不展開。
4、相同顏色值在全局是同一份,如果對其改變獲取后的colorDrawable值,會導(dǎo)致其它所有使用的地方都改變,可以采用mutable避免。 這個其實不能算作坑,是自己代碼沒有看仔細(xì)。
5、華為p8手機(jī),如果service與ui不在同一進(jìn)程,service中監(jiān)控網(wǎng)絡(luò)的BroadcastReciver 會收不到網(wǎng)絡(luò)連接的廣播,但是能收到斷開的廣播,這個應(yīng)該也是華為自己的優(yōu)化,但是ui中的連接與斷開都能收到廣播。
6: Android 在4.4后更新了webview內(nèi)核,在5.0前在webview中,不用的域可以讀取其它域設(shè)置的cookie,但是在5.0開始,系統(tǒng)默認(rèn)值改為了false。這樣會導(dǎo)致之前以前采用舊方法的不能獲取到。(其實在我看來,確實不應(yīng)該跨域來讀取cookie,多不安全)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, true);
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助。
- Android開發(fā)騰訊驗證碼遇到的坑
- Android—基于微信開放平臺v3SDK開發(fā)(微信支付填坑)
- Android開發(fā)手機(jī)無線調(diào)試的方法
- Android開發(fā)教程之獲取系統(tǒng)輸入法高度的正確姿勢
- Android開發(fā)解決popupWindow重疊報錯問題
- 使用Win10+Android+夜神安卓模擬器,搭建ReactNative開發(fā)環(huán)境
- Android快速開發(fā)系列 10個常用工具類實例代碼詳解
- Android開發(fā)筆記之如何正確獲取WebView的網(wǎng)頁Title
- Android開發(fā)圖片水平旋轉(zhuǎn)180度方法
- Android Studio中使用jni進(jìn)行opencv開發(fā)的環(huán)境配置方法
- Android UI開發(fā)中所遇到的各種坑
相關(guān)文章
Android自定義View實現(xiàn)帶音效和震動的SeekBar
這篇文章主要為大家詳細(xì)介紹了Android如何自定義View實一個帶音效和震動的SeekBar,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-03-03
解決Android 6.0獲取wifi Mac地址為02:00:00:00:00:00問題
這篇文章主要介紹了Android 6.0獲取wifi Mac地址為02:00:00:00:00:00的解決方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-11-11
ListView的Adapter使用(綁定數(shù)據(jù)) 之 自定義每一項的布局去綁定數(shù)據(jù)
之前寫的綁定數(shù)據(jù)是只是簡單的綁定了字符串,這次我們將一次綁定多條數(shù)據(jù)并且嘗試用自定義的布局。在這篇文章中首先講解的是用Hashmap 去綁定數(shù)據(jù),第二個例子,講解自定義布局然后綁定數(shù)據(jù)2013-06-06
Android開發(fā)手冊Chip監(jiān)聽及ChipGroup監(jiān)聽
這篇文章主要為大家介紹了Android開發(fā)手冊Chip監(jiān)聽及ChipGroup監(jiān)聽,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06
Android發(fā)送GET與POST請求的DEMO詳解
本篇文章是對Android發(fā)送GET與POST請求的DEMO進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06

