Serializable(接口)
通过intent 的bundle传递参数
Bundle bundle = new Bundle();
bundle.putSerializable(IntentKeys.IMG_ARR_ENVIR_IMG, mArrListEnvir_img); intent.putExtras(bundle);mListEnvir = (ArrayList<EnvirImg>) (bundle
.getSerializable(IntentKeys.IMG_ARR_ENVIR_IMG));
Parcelable(接口)
通过intent 的bundle传递参数
Bundle bundle = new Bundle();
bundle.putParcelable(IntentKeys.IMG_ARR_ENVIR_IMG, mArrListEnvir_img);intent.putExtras(bundle);
import android.graphics.Bitmap;
import android.os.Parcel;import android.os.Parcelable;public class UploadPic implements Parcelable{
private String id; private String sdPath; private String webPath; private Bitmap bmp; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getSdPath() { return sdPath; } public void setSdPath(String sdPath) { this.sdPath = sdPath; } public String getWebPath() { return webPath; } public void setWebPath(String webPath) { this.webPath = webPath; } public Bitmap getBmp() { return bmp; } public void setBmp(Bitmap bmp) { this.bmp = bmp; }@Override
public int describeContents() { return 0; } @Override public void writeToParcel(Parcel parcel, int flags) { parcel.writeString(id); parcel.writeString(sdPath); parcel.writeString(webPath); bmp.writeToParcel(parcel, 0); } public static final Parcelable.Creator<UploadPic> CREATOR = new Creator<UploadPic>() { public UploadPic createFromParcel(Parcel source) { UploadPic pic = new UploadPic(); pic.id = source.readString(); pic.sdPath = source.readString(); pic.webPath = source.readString(); //传递string数据 pic.bmp = Bitmap.CREATOR.createFromParcel(source);//传递bitmap数据 return pic; } public UploadPic[] newArray(int size) { return new UploadPic[size]; } }; }
Parcelable比Serializable效率高
parcelable也不适合传输大量图片数据
android.os.TransactionTooLargeException 不适合传大量数据尤其bitmap intent跳转的时候无缝传递数据pacicl
导致原因是:Binder传输的数据太大如果Binder的参数或返回值太大,不适合的事务缓冲区,然后调用将失败,并将被抛出TransactionTooLargeException。解决方法:不要将大量数据传入Binder