码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2015-08-15 00:12:57      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

 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 }

 

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

标签:

原文地址:http://www.cnblogs.com/gaojinhua/p/4731456.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!