gpt4 book ai didi

android - ByteArray Property Too Large to send within putExtra ("obj", obj) of intent 打开另一个 Activity 时

转载 作者:行者123 更新时间:2023-11-29 23:06:07 26 4
gpt4 key购买 nike

我有一个具有 string、int、double、byte[] 属性的对象。我的 byte[] 正在存储来自数据库的图像,因为我将图像以字节形式存储在我的表中。

问题是,当我序列化对象并通过 intent.puteExtra("obj", obj) 传递对象时,应用程序崩溃,控制台中没有任何错误。

然后我让我的 byte[] property = byte[1] 并且所有的工作都在 activity swithed 并且数据通过了 intent。

这是我的销售对象:

import android.media.Image;
import android.os.Parcel;
import android.os.Parcelable;

import java.io.Serializable;
import java.util.Date;

public class Sell extends Product implements Serializable
{
public byte[] Image1;
public byte[] Image1a;

public byte[] Image2;
public byte[] Image3;
public byte[] Image4;
public String postcode;
public double postage;
public int isDelivered ;





public Sell(int p_Id, String p_u_id, double price, String title, String description, int category, String tags,
byte[] image1, byte[] image2, byte[] image3, byte[] image4
, String postcode, double postage, int isDelivered, String date, int type)
{

super(p_Id, p_u_id,price,title,description,category,tags, type, date);
this.Image1 = image1;
this.Image2 = image2;
this.Image3 = image3;
this.Image4 = image4;
this.postcode = postcode;
this.postage = postage;
this.isDelivered = isDelivered;


}

}

这是我的产品对象:

package com.asianretail.trikam.asianretail;

import android.os.Parcel;
import android.os.Parcelable;

import java.io.Serializable;

public class Product implements Serializable {

public int p_Id;
public String P_U_Id;
public double Price;
public int Category;
public String Tags;
public String Title;
public String Description;
public int Type;
public String Date;

public Product(int p_Id, String p_u_id, double price, String title, String description, int category, String tags, int type, String date)
{

this.Date = date;
this.p_Id = p_Id;
this.P_U_Id = p_u_id;
this.Price = price;
this.Title = title;
this.Description = description;
this.Category = category;
this.Tags = tags;
this.Type = type;

}
}

要从 fragment 开始 Activity ,我使用这个:

Product prod = null;
for(int i = 0; i < pObj.size(); i++){
if(((Product)pObj.get(i)).p_Id == ((int)v.getTag())){
prod = (Product)pObj.get(i);
}
}
Bundle bundle = new Bundle();
bundle.putSerializable("valueProd", prod);

Intent i = new Intent(getActivity(), ProductActivity.class);
i.putExtra("bundleProd", bundle);
startActivity(i);

最佳答案

最好将字节数组写入文件并将文件的 url 传递给 bundle。你不应该在 bundle 中传递图像,因为它可能会尝试访问比分配的内存更多的内存,以防你的字节数组太大。

关于android - ByteArray Property Too Large to send within putExtra ("obj", obj) of intent 打开另一个 Activity 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56508288/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com