greenDao與Parcelable均可以實現對Object數據的存儲。java
1. greenDao數據庫
greenDAO是一個能夠幫助Android開發者快速將Java對象映射到SQLite數據庫的表單中的ORM解決方案,經過使用一 個簡單的面向對象API,開發者能夠對Java對象進行存儲、更新、刪除和查詢。ide
2. Parcelablethis
Parcelable是Android中用於對Object數據進行序列化和反序列化的接口。spa
注意:greendao自動生成的info能夠繼承Parcelable接口,實現序列化和反序列數據存儲。.net
例:code
public class ContractDeatilInfo implements Parcelable{ /** Not-null value. */ private String id; private String name; private String party_a; private String party_b; public ContractDeatilInfo() { } public ContractDeatilInfo(String id) { this.id = id; } public ContractDeatilInfo(String id, String name, String party_a, String party_b, String sign_date, String value, String remarks) { this.id = id; this.name = name; this.party_a = party_a; this.party_b = party_b; } /** Not-null value. */ public String getId() { return id; } /** Not-null value; ensure this value is available before it is saved to the database. */ public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getParty_a() { return party_a; } public void setParty_a(String party_a) { this.party_a = party_a; } public String getParty_b() { return party_b; } public void setParty_b(String party_b) { this.party_b = party_b; } // 以上是greendao自動生成的info,如下是實現Parcelable接口的內容 @Override public int describeContents() { return 0; } //實現序列化,j @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(id); dest.writeString(name); dest.writeString(party_a); dest.writeString(party_b); } //實現反序列化,從Parcel解析出來 public static final Parcelable.Creator<ContractDeatilInfo> CREATOR = new Creator<ContractDeatilInfo>() { @Override public ContractDeatilInfo[] newArray(int size) { return new ContractDeatilInfo[size]; } @Override public ContractDeatilInfo createFromParcel(Parcel source) { ContractDeatilInfo info = new ContractDeatilInfo(); info.id = source.readString(); info.name = source.readString(); info.party_a = source.readString(); info.party_b = source.readString(); return info; } }; }