当前位置: 移动技术网 > 移动技术>移动开发>Android > Android开发中那些需要注意的坑

Android开发中那些需要注意的坑

2019年07月24日  | 移动技术网移动技术  | 我要评论

这个是看知乎的时候发现的一个问题,感觉挺有意思,就将自己遇到的坑记录下来。

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花屏,由于过度绘制导致,关闭硬件加速, 尤其是使用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);
    }

以上就是本文的全部内容,希望对大家的学习有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网