在Android中通过intent只能传递基本类型的数据,如果想要传递自定义的javabean,必须实现Serializable或者Parcelable接口。Parcelable接口是在Android新引入的接口。使用方法如下:

 
  1. public class DownloadItem  implements Parcelable{ 
  2.  
  3.     private String url; 
  4.     private String  gameName; 
  5.     private String gamePkgName; 
  6.     private int total_bytes; 
  7.     private int current_bytes; 
  8.     private String path; 
  9.     public DownloadItem(){}; 
  10.  
  11.     public DownloadItem(String url, String gameName, String gamePkgName, 
  12.             int total_bytes, int current_bytes, String path) { 
  13.         super(); 
  14.         this.url = url; 
  15.         this.gameName = gameName; 
  16.         this.gamePkgName = gamePkgName; 
  17.         this.total_bytes = total_bytes; 
  18.         this.current_bytes = current_bytes; 
  19.         this.path = path; 
  20.     } 
  21.  
  22.     @Override 
  23.     public String toString() { 
  24.         return "DownloadItem [url=" + url + ", gameName=" + gameName 
  25.                 + ", gamePkgName=" + gamePkgName + ", total_bytes=" 
  26.                 + total_bytes + ", current_bytes=" + current_bytes + ", path=" 
  27.                 + path + "]"
  28.     } 
  29.  
  30.     public String getUrl() { 
  31.  
  32.         return url; 
  33.     } 
  34.  
  35.     public void setUrl(String url) { 
  36.         this.url = url; 
  37.     } 
  38.  
  39.     public String getGameName() { 
  40.         return gameName; 
  41.     } 
  42.  
  43.     public void setGameName(String gameName) { 
  44.         this.gameName = gameName; 
  45.     } 
  46.  
  47.     public String getGamePkgName() { 
  48.         return gamePkgName; 
  49.     } 
  50.  
  51.     public void setGamePkgName(String gamePkgName) { 
  52.         this.gamePkgName = gamePkgName; 
  53.     } 
  54.  
  55.     public int getTotal_bytes() { 
  56.         return total_bytes; 
  57.     } 
  58.  
  59.     public void setTotal_bytes(int total_bytes) { 
  60.         this.total_bytes = total_bytes; 
  61.     } 
  62.  
  63.     public int getCurrent_bytes() { 
  64.         return current_bytes; 
  65.     } 
  66.  
  67.     public void setCurrent_bytes(int current_bytes) { 
  68.         this.current_bytes = current_bytes; 
  69.     } 
  70.  
  71.     public String getPath() { 
  72.         return path; 
  73.     } 
  74.  
  75.     public void setPath(String path) { 
  76.         this.path = path; 
  77.     } 
  78.  
  79.     @Override 
  80.     public int describeContents() { 
  81.         // TODO Auto-generated method stub 
  82.         return 0
  83.     } 
  84.  
  85.     @Override 
  86.     public void writeToParcel(Parcel dest, int flags) { 
  87.  
  88.  
  89.         dest.writeString(this.url); 
  90.         dest.writeString(this.gameName); 
  91.         dest.writeString(this.gamePkgName); 
  92.         dest.writeInt(this.total_bytes); 
  93.         dest.writeInt(this.current_bytes); 
  94.         dest.writeString(this.path); 
  95.     } 
  96.  
  97.     public static final Parcelable.Creator<DownloadItem> CREATOR = new Parcelable.Creator<DownloadItem>() { 
  98.  
  99.         @Override 
  100.         public DownloadItem createFromParcel(Parcel source) { 
  101.             return new DownloadItem(source.readString(),source.readString(),source.readString(),source.readInt(),source.readInt(),source.readString()); 
  102.         } 
  103.  
  104.         @Override 
  105.         public DownloadItem[] newArray(int size) { 
  106.             return new DownloadItem[size]; 
  107.         } 
  108.     };