gpt4 book ai didi

java - 无法在另一个 Activity 中发送大型可分割对象数组

转载 作者:行者123 更新时间:2023-12-01 11:33:34 34 4
gpt4 key购买 nike

我有两个 Activity ,第一个 Activity 说 Activity1 只是从服务器获取数据,过滤它并将其保存在可分割对象的数组列表中,同时显示加载屏幕。之后,Activity1 将其收集的数据传递给 Acitivty2,Acitivty2 将其显示到 2 个子 fragment 中。

我的问题是,当 Activity1 中的数据列表很少时,它会成功传递给 Activity2,但是如果不是,则 Activity 2 将不会显示并启动我的另一个 Activity,即 MainAcitivty

这是我用来从 Activity1 启动 Activity2 的函数

Bundle mBundle = new Bundle();       
Intent intent = new Intent(Activity_Viewdata_loader.this, Activity_Viewdata.class);
mBundle.putParcelableArrayList("myList", sneardatalist);
intent.putExtras(mBundle);

这是我的 Activity2,它是接收者

Bundle mBundle = getIntent().getExtras();
sneardatalist= mBundle.getParcelableArrayList("myList");

我的可分割类看起来像这样

public class sentdata implements Parcelable  {

private int _id;
private String _data="";
private String _lat="";
private String _long="";
private String _img="";
private String _imgP="";
private int _sntvia;
private String _snttime="";
private String _template="";

public sentdata(){}
public sentdata( String data, String lat, String longt, String img, String imgp, int sntvia, String sntime, String template ){
this._data = data;
this._lat = lat;
this._long = longt;
this._img = img;
this._imgP = imgp;
this._sntvia = sntvia;
this._snttime = sntime;
this._template = template;
}

public sentdata( int id, String data, String lat, String longt, String img, String imgp, int sntvia, String sntime, String template ){
this._id = id;
this._data = data;
this._lat = lat;
this._long = longt;
this._img = img;
this._imgP = imgp;
this._sntvia = sntvia;
this._snttime = sntime;
this._template = template;
}

public int getid(){
return this._id;
}

public void setid(int id){
this._id = id;
}
public void setdata(String data){
this._data = data;
}

public String getdata(){
return this._data;
}

public void setlat(String lat){
this._lat = lat;
}

public String getlat(){
return this._lat;
}

public void setlong(String longt){
this._long = longt;

}

public String getlong(){
return this._long;
}

public void setimg(String img){
this._img = img;

}

public String getimg(){
return this._img;

}

public void setimgP (String imgP){
this._imgP = imgP;
}

public String getimgP(){
return this._imgP;
}

public void setsentvia(int sntvia){
this._sntvia = sntvia;
}

public int getsentvia(){
return this._sntvia;
}

public void setsentTime(String sentime ){
this._snttime = sentime;
}

public String getsenttime(){
return this._snttime;
}

public void settemp (String tmp ){
this._template = tmp;
}

public String gettmp(){
return this._template;
}

@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}

public sentdata(Parcel source){
_id = source.readInt();
_data = source.readString();
_lat = source.readString();
_long = source.readString();
_img = source.readString();
_imgP = source.readString();
_sntvia = source.readInt();
_snttime = source.readString();
_template = source.readString();
}

@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeInt(_id);
dest.writeString(_data);
dest.writeString(_lat);
dest.writeString(_long);
dest.writeString(_img);
dest.writeString(_imgP);
dest.writeInt(_sntvia);
dest.writeString(_snttime);
dest.writeString(_template);
}

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

@Override
public sentdata createFromParcel(Parcel source) {
// TODO Auto-generated method stub
return new sentdata(source);
}

@Override
public sentdata[] newArray(int size) {
// TODO Auto-generated method stub
return new sentdata[size];
}
};
}

请帮助我..我真的不知道该怎么办。我想到了其他方法,但我不想仅仅因为数据的大小而放弃这个简单的方法。可能还有其他我必须做或不知道的事情,为什么它不会传递大尺寸数组列表。

最佳答案

使用可分割对象的数组列表创建一个类,将可分割对象设置为数组列表,并通过 bundle 将该类对象传递到下一个 Activity 。

关于java - 无法在另一个 Activity 中发送大型可分割对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30228301/

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