您好,登錄后才能下訂單哦!
Serializable(接口)
通過intent 的bundle傳遞參數(shù)
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傳遞參數(shù)
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數(shù)據(jù)
pic.bmp = Bitmap.CREATOR.createFromParcel(source);//傳遞bitmap數(shù)據(jù)
return pic;
}
public UploadPic[] newArray(int size) {
return new UploadPic[size];
}
};
}
Parcelable比Serializable效率高
parcelable也不適合傳輸大量圖片數(shù)據(jù)
android.os.TransactionTooLargeException 不適合傳大量數(shù)據(jù)尤其bitmap intent跳轉(zhuǎn)的時候無縫傳遞數(shù)據(jù)pacicl
導(dǎo)致原因是:Binder傳輸?shù)臄?shù)據(jù)太大
如果Binder的參數(shù)或返回值太大,不適合的事務(wù)緩沖區(qū),然后調(diào)用將失敗,并將被拋出TransactionTooLargeException。
解決方法:
不要將大量數(shù)據(jù)傳入Binder
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。