无法在另一个行为中发送大量可分配对象

时间:2015-05-14 02:25:45

标签: java android arraylist parcelable

我有两个活动,第一个活动说Activity1只是从服务器获取数据过滤它并在显示加载屏幕时将其保存在parcelable对象的arraylist中。之后,Activity1将收集的数据传递给Acitivty2,后者将其显示为2个子片段。

我的问题是,当activity1中的数据列表很少时,它会成功传递给activity2,但是当它不是时,acitivity 2将不会显示并启动我的其他活动,即 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"); 

我的parcelable类看起来像这样

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];
        }   
    };
}

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

1 个答案:

答案 0 :(得分:1)

使用parcelable对象的arraylist创建一个类,将parcelable对象设置为arraylist,并通过bundle将该类对象传递给下一个活动。