Android開發中那些需要注意的坑_Android

來源:互聯網
上載者:User

這個是看知乎的時候發現的一個問題,感覺挺有意思,就將自己遇到的坑記錄下來。

1、Andorid L theme colorPrimary 不能使用帶有alpha的顏色值,否則會有異常拋出, 直接判斷了是否alpha是否等於0或者255,其他都會異常

@Overrideprotected 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 activityif (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花屏,由於過度繪製導致,關閉硬體加速, 尤其是使用webview後,可能會有大機率出現。

3、華為手機被KILL一系列問題

使用者可以設定某個應用是否後台保護,按照華為的功能說明,理解為,如果不保護,那鎖屏後程式將無法保持運行,也就是進程可能被KILL

新安裝應用後,華為會給出選項,是否保持,這個預設選項上存在問題,有的應用預設不允許,有的應用預設就允許。

關於耗電高被KILL問題。

關於鎖屏後網路被切斷問題。鎖屏就算保護,而網路或者SOCKET也可能被主動切斷。

華為自己給出了BASTET系統解決方案,具體不展開。
4、相同顏色值在全域是同一份,如果對其改變擷取後的colorDrawable值,會導致其它所有使用的地方都改變,可以採用mutable避免。 這個其實不能算作坑,是自己代碼沒有看仔細。

5、華為p8手機,如果service與ui不在同一進程,service中監控網路的BroadcastReciver 會收不到網路連接的廣播,但是能收到斷開的廣播,這個應該也是華為自己的最佳化,但是ui中的串連與斷開都能收到廣播。

6: Android 在4.4後更新了webview核心,在5.0前在webview中,不用的域可以讀取其它網域設定的cookie,但是在5.0開始,系統預設值改為了false。這樣會導致之前以前採用舊方法的不能擷取到。(其實在我看來,確實不應該跨域來讀取cookie,多不安全)

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {      CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, true);    }

以上就是本文的全部內容,希望對大家的學習有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.