`
jianweicao
  • 浏览: 117243 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Andriod Parcelable 读写 boolean(布尔值)的方法

 
阅读更多

源自:http://stackoverflow.com/questions/6201311/how-to-read-write-a-boolean-when-implementing-the-parcelable-interface?answertab=votes#tab-top

 

Here's how I'd do it...

writeToParcel:

dest.writeByte((byte)(myBoolean ?1:0));//if myBoolean == true, byte == 1

readFromParcel:

myBoolean =in.readByte()!=0;//myBoolean == true if byte != 0

I think != 0 should be better, because 0 is a little bit faster to load, and in most weakly-typed languages all non-zero numbers are true

 

 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics