Android开发中那些需要注意的坑
这个是看知乎的时候发现的一个问题,感觉挺有意思,就将自己遇到的坑记录下来。
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); }
以上就是本文的全部内容,希望对大家的学习有所帮助。
- Android开发腾讯验证码遇到的坑
- Android—基于微信开放平台v3SDK开发(微信支付填坑)
- Android开发手机无线调试的方法
- Android开发教程之获取系统输入法高度的正确姿势
- Android开发解决popupWindow重叠报错问题
- 使用Win10+Android+夜神安卓模拟器,搭建ReactNative开发环境
- Android快速开发系列 10个常用工具类实例代码详解
- Android开发笔记之如何正确获取WebView的网页Title
- Android开发图片水平旋转180度方法
- Android Studio中使用jni进行opencv开发的环境配置方法
- Android UI开发中所遇到的各种坑
相关文章
Android Scroll实现弹性滑动_列表下拉弹性滑动的示例代码
下面小编就为大家分享一篇Android Scroll实现弹性滑动_列表下拉弹性滑动的示例代码,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2018-01-01Android5.0+ CollapsingToolbarLayout使用详解
这篇文章主要为大家详细介绍了Android5.0+ CollapsingToolbarLayout使用,感兴趣的小伙伴们可以参考一下2016-09-09Android实现录音方法(仿微信语音、麦克风录音、发送语音、解决5.0以上BUG)
大家平时在使用微信qq聊天时经常会发送语音功能,今天小编给大家带来了基于android实现录音的方法仿微信语音、麦克风录音、发送语音、解决5.0以上BUG,需要的朋友参考下吧2018-04-04Android Navigation重建Fragment问题分析及解决
这篇文章主要介绍了Android Navigation重建Fragment问题分析及解决,文章通过围绕主题展开详细的内容介绍,具有一定的参考价值,需要的小伙伴可以参考一下2022-09-09
最新评论