Android对象类系列化public class User implements Parcelable

 1 package com.gaojinhua.android.activitymsg;
 2 
 3 import android.os.Parcel;
 4 import android.os.Parcelable;
 5 
 6 /**
 7  * Created by Gaojinhua on 2015/8/14.
 8  */
 9 public class User implements Parcelable {
10     private String name;
11     private int age;
12 
13     public User(String name, int age) {
14         this.name = name;
15         this.age = age;
16     }
17 
18 
19     public void setName(String name) {
20         this.name = name;
21     }
22 
23     public String getName() {
24         return name;
25     }
26 
27     public void setAge(int age) {
28         this.age = age;
29     }
30 
31     public int getAge() {
32         return age;
33     }
34 
35     @Override
36     public int describeContents() {
37         return 0;
38     }
39 
40     @Override
41     public void writeToParcel(Parcel dest, int flags) {
42         dest.writeString(getName());
43         dest.writeInt(getAge());
44     }
45 
46     public static final Creator<User> CREATOR = new Creator<User>() {
47         @Override
48         public User createFromParcel(Parcel source) {
49             return new User(source.readString(), source.readInt());
50         }
51 
52         @Override
53         public User[] newArray(int size) {
54             return new User[size];
55         }
56     };
57 
58 
59 }

 

转载于:https://www.cnblogs.com/gaojinhua/p/4731456.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值