需要明确捆绑什么
捆绑对象以供以后检索时,是否必须将对象捆绑在这些对象内?
例如,如果我有一个代表纸牌游戏中玩家的对象,并且在其中实例化了一个代表玩家手牌的对象,那么我是否已将内部对象保存到包中,还是自动包含在外部对象中?
When bundling an object for later retrieval do I have to bundle objects within those objects?
For example, if I have an object that represents a player in a card game and within that I instantiate an object that represents the player's hand, do I have save the inner object to the bundle or is that automatically included with the outer one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能捆绑任何旧的
对象
,它必须是String
或基元,例如boolean
、integer
、 “字节”或这些简单事物的数组。在本例中是的,String[]
数组的内容与 Bundle 一起保存。对于更复杂的结构,您可以在对象类中使用
Parcelable
实现,但您需要确保对象将所有必要的信息保存到其 Parcel 中并恢复它。You cannot bundle any old
Object
, it has to be aString
or a primitive such asboolean
,integer
, 'byte' or an array of these simple things. In this case yes, the contents of aString[]
array are saved with the Bundle.For more complex structures you can use implement the
Parcelable
in your object class, but it will be up to you to make sure the object saves all necessary information to it's Parcel and restores it.java.ui.Serializable 是值得检查的东西。只要您的类和所有必需的成员也实现 Serialized 接口,它几乎可以自动捆绑类及其成员变量。
http://www.tutorialspoint.com/java/java_serialization.htm
java.ui.Serializable is something worth checking. It pretty much automates bundling class and its member variables as long as your class and all required members implement Serializable interface too.
http://www.tutorialspoint.com/java/java_serialization.htm