Activitie之間傳對(duì)象,通過(guò)Parcelable(轉(zhuǎn))
對(duì)象必須實(shí)現(xiàn)Serializable,對(duì)象代碼如下:
- import java.io.Serializable;
- import android.graphics.drawable.Drawable;
- /**
- * 包括軟件信息及評(píng)論
- * */
- public class MyApplicationInfo extends Object implements Serializable{
- /**
- *
- */
- private static final long serialVersionUID = -5151302508106116740L;
- //程序名稱
- private String title;
- //程序名稱
- private String label;
- //程序版本
- private String version;
- //新版本
- private String newVersion;
- //內(nèi)容介紹
- private String content;
- //作者
- private String author;
- //圖標(biāo)鏈接
- private String icon;
- //圖標(biāo)
- private Drawable dicon;
- //演示圖片動(dòng)態(tài)數(shù)組
- private String[] Demos;
- //價(jià)格
- private String price;
- //總共5星,以數(shù)字形式存儲(chǔ)
- private String star;
- //鏈接地址
- private String detailaddress;
- //評(píng)論包括:評(píng)論者、評(píng)論時(shí)間、評(píng)論內(nèi)容、評(píng)論星級(jí)
- private Details details;
- //包名
- private String packageName;
- //啟動(dòng)程序Class
- private String className;
- public String getTitle() {
- return title;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- public String getVersion() {
- return version;
- }
- public void setVersion(String version) {
- this.version = version;
- }
- public String getContent() {
- return content;
- }
- public void setContent(String content) {
- this.content = content;
- }
- public String getAuthor() {
- return author;
- }
- public void setAuthor(String author) {
- this.author = author;
- }
- public String getIcon() {
- return icon;
- }
- public void setIcon(String icon) {
- this.icon = icon;
- }
- public String getPrice() {
- return price;
- }
- public void setPrice(String price) {
- this.price = price;
- }
- public String getStar() {
- return star;
- }
- public void setStar(String star) {
- this.star = star;
- }
- public String getDetailaddress() {
- return detailaddress;
- }
- public void setDetailaddress(String detailaddress) {
- this.detailaddress = detailaddress;
- }
- public String[] getDemos() {
- return Demos;
- }
- public void setDemos(String[] demos) {
- Demos = demos;
- }
- public Details getDetails() {
- return details;
- }
- public void setDetails(Details details) {
- this.details = details;
- }
- public String getPackageName() {
- return packageName;
- }
- public void setPackageName(String packageName) {
- this.packageName = packageName;
- }
- public Drawable getDicon() {
- return dicon;
- }
- public void setDicon(Drawable dicon) {
- this.dicon = dicon;
- }
- public String getLabel() {
- return label;
- }
- public void setLabel(String label) {
- this.label = label;
- }
- public String getNewVersion() {
- return newVersion;
- }
- public void setNewVersion(String newVersion) {
- this.newVersion = newVersion;
- }
- public String getClassName() {
- return className;
- }
- public void setClassName(String className) {
- this.className = className;
- }
- }
自定義:AppParcelable
- import android.os.Parcel;
- import android.os.Parcelable;
- import com.tcad.marketassistant.vo.MyApplicationInfo;
- public class AppParcelable implements Parcelable {
- private MyApplicationInfo info;
- public AppParcelable(Parcel source){
- info = (MyApplicationInfo)source.readValue(MyApplicationInfo.class.getClassLoader());
- }
- public AppParcelable(MyApplicationInfo info){
- this.info = info;
- }
- public int describeContents() {
- return 0;
- }
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeValue(info);
- }
- public static final Parcelable.Creator<AppParcelable> CREATOR = new Parcelable.Creator<AppParcelable>() {
- public AppParcelable createFromParcel(Parcel source) {
- return new AppParcelable(source);
- }
- public AppParcelable[] newArray(int size) {
- // return new AppParcelable[size];
- throw new UnsupportedOperationException();
- }
- };
- public MyApplicationInfo getInfo(){
- return info;
- }
- }
調(diào)用代碼,發(fā)送:
- AppParcelable parcelable = new AppParcelable(info);
- //Info為MyApplicationInfo對(duì)象
- // 發(fā)送對(duì)象
- intent.putExtra("app_parcelable", parcelable);
- startActivity(intent);
接收:
- AppParcelable p = getIntent().getParcelableExtra("app_parcelable");
- MyApplicationInfo info = p.getInfo();
posted on 2010-09-10 16:00 九寶 閱讀(2138) 評(píng)論(0) 編輯 收藏 所屬分類: android