开发学院手机开发Android 开发 Android中Intent传递对象的两种方法(Serializable... 阅读

Android中Intent传递对象的两种方法(Serializable,Parcelable)

 2010-10-19 20:18:07 来源:WEB开发网   
核心提示:this.bookName = bookName;}public String getAuthor() {return author;}public void setAuthor(String author) {this.author = author;}public int getPublishTime() {ret

this.bookName = bookName;

}

public String getAuthor() {

return author;

}

public void setAuthor(String author) {

this.author = author;

}

public int getPublishTime() {

return publishTime;

}

public void setPublishTime(int publishTime) {

this.publishTime = publishTime;

}

public static final Parcelable.Creator CREATOR = new Creator() {

public Book createFromParcel(Parcel source) {

Book mBook = new Book();

mBook.bookName = source.readString();

mBook.author = source.readString();

mBook.publishTime = source.readInt();

return mBook;

}

public Book[] newArray(int size) {

return new Book[size];

}

};

public int describeContents() {

return 0;

}

public void writeToParcel(Parcel parcel, int flags) {

parcel.writeString(bookName);

parcel.writeString(author);

parcel.writeInt(publishTime);

}

}

第四步:修改ObjectTranDemo.java,并且新建两个Activity,一个是ObjectTranDemo1.java,别一个是ObjectTranDemo2.java.分别用来显示Person对像数据,和Book对象数据:,代码分别如下:

ObjectTranDemo.java:

package com.tutor.objecttran;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

public class ObjectTranDemo extends Activity implements OnClickListener {

private Button sButton,pButton;

public final static String SER_KEY = "com.tutor.objecttran.ser";

public final static String PAR_KEY = "com.tutor.objecttran.par";

上一页  1 2 3 4 5 6 7 8 9  下一页

Tags:Android Intent 传递

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接