Andriod开发中,有哪些需要注意的坑?

400 查看

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花屏,由于过度绘制导致,关闭硬件加速。
3:华为的受保护应用问题,华为有自己的一套连接机制,时间一长就把网络给切断掉。
4:相同颜色值在全局是同一份,如果对其改变获取后的colorDrawable值,会导致其它所有使用的地方都改变,可以采用mutable避免。
5:华为p8手机,如果service与ui不在同一进程,service中监控网络的BroadcastReciver 收不到网络连上的广播,但是能收到断开的广播。
6:建议做手游或者app测试时使用第三方测试平台,比如像Testbird云测平台(现在注册送免费调试时间)之类的,方便快捷,且结论更准确。