遇到Android N的第一个小坑

作者: goeasyway | 来源:发表于2016-05-19 20:29 被阅读1783次

Google 2016 I/O大会正如火如荼,正好这两天拿到一部工程机,就测试一下现有的应用在Android N (Preview 1)上的表现。一上发现框架部份出问题,整个应用无法正常启动。

Debug跟踪了一会,发现问题竟然出在Cursor.getBlog这个接口上。如下是Android M(6.0.1_r10)的源码:


/**    * Returns the value of the requested column as a byte array.    *    *

The result and whether this method throws an exception when the

* column value is null or the column type is not a blob type is

* implementation-defined.

*

* @param columnIndex the zero-based index of the target column.

* @return the value of that column as a byte array.

*/

byte[] getBlob(int columnIndex);

在前面的版本如果数据表中这项值没有赋值的话,getBlob是会返回null的。之前我们的代码要根据这个值为null或者返回的byte[]长度为0时重新获取一次数据,而这次在Android N的手机上发现,数据表中这一项没有赋值的话,getBlob会返回长度为1的默认byte[](byte[0]的值为0),从而导致后面重新获取数据的逻辑一直不被执行。

相关文章

网友评论

  • DylanW:笔误一枚,Cursor.getBlog应该是源码中的getBlob
    goeasyway:@DylanW 确实是,非常感谢。
  • chonrp27512:弱弱问一下,博主是怎么跟踪源码的。我没试过跟踪到源码进去。。
    chonrp27512:👌🏻谢谢。
    goeasyway:@chonrp27512 其实我很多时候是直接看Google的AOSP代码

本文标题:遇到Android N的第一个小坑

本文链接:https://www.haomeiwen.com/subject/gtmgrttx.html