Intent传递简单对象与集合
来源:互联网 发布:今日头条济南数据分析 编辑:程序博客网 时间:2024/06/05 13:23
们在Intent传递传递对象,可以有三种方式,实现Serializable接口、实现Parcelable接口,使用json格式序列化与反序列化。
在此我们使用第二方式,现实Parcelable接口,实现Parcelable需要以下操作。
1.writeToParcel 方法:该方法将类的数据写入外部提供的Parcel中。
2.describeContents 方法:返回内容描述信息的资源ID。
3.静态的Parcelable.Creator接口,本接口有以下方法两方法:
3.1 createFormParcel(Parcel in):实现从parcle实例中创建出类的实例的功能。
3.2 newArray(int size): 创建一个类型为T,长度为size的数组。
www.wwkxii.com
例子1:User 对象创建
- public class User implements Parcelable{
- private Integer userId;
- private String userName;
- @Override
- public int describeContents() {
- return 0;
- }
- /**
- * 注意:序列化与反序列化顺序必须要一样
- * @param parcel
- */
- public User(Parcel source){
- this.userId =source.readInt();
- this.userName = source.readString();
- }
- public User(Integer userId, String userName) {
- super();
- this.userId = userId;
- this.userName = userName;
- }
- /**
- * 序列化
- */
0 0
- Intent传递简单对象与集合
- Intent传递简单对象与集合
- Intent传递简单对象与集合
- Intent 传递对象和集合
- android Intent传递对象和集合
- intent传递对象以及list集合
- AndroidのIntent传递集合对象
- android intent传递对象和集合
- Intent传值 与 传递类对象
- Intent 传递简单类型, 数组, Object对象,与ArrayList<T> 类型数据
- Intent传递集合数据
- Intent传递map集合
- 25、Android中通过Intent传递对象、集合问题
- Android中通过Intent传递对象、集合问题
- Android中通过Intent传递对象、集合问题
- Android中通过Intent传递对象、集合问题
- Intent之对象传递(Serializable传递对象和对象集合)
- Intent之对象传递(Parcelable传递对象和对象集合)
- APPWeb+PHP5+SQLite3在S3C6410上移植之三
- JQuery-选择器整理
- POJ 1002
- APPWeb+PHP5+SQLite3在S3C6410上移植之四
- ZOJ 3635 树状数组+二分
- Intent传递简单对象与集合
- samba服务器的搭建(scurity=share)
- 第七章 快速排序
- HDU 1598 find the most comfortable road
- 关于计时器NSTimer 的使用
- Android菜鸟在成长—ListView复杂列表信息项
- POJ 2063 Investment
- [Android]ListView性能优化之视图缓存
- oracle导入导出