Java putParcelableArrayListExtra和黑屏
我有一个自定义类,它实现了Java putParcelableArrayListExtra和黑屏,java,android,parcelable,Java,Android,Parcelable,我有一个自定义类,它实现了Parcelable,并将其用作自定义arraylist 当我使用putParcelableArrayListExtra和400行时,它可以正常工作,但1000行则不行。我有黑屏和应用程序锁定。怎么了 编辑: 我把它发送到这里,我没有在其他活动中使用它 Intent intent = new Intent().setClass(getApplicationContext(), ArtActivity.class); intent.putParcelableArrayLi
Parcelable
,并将其用作自定义arraylist
当我使用putParcelableArrayListExtra
和400行时,它可以正常工作,但1000行则不行。我有黑屏和应用程序锁定。怎么了
编辑:
我把它发送到这里,我没有在其他活动中使用它
Intent intent = new Intent().setClass(getApplicationContext(), ArtActivity.class);
intent.putParcelableArrayListExtra ("mylist", list);
startActivityForResult(intent, SECONDARY_ACTIVITY_REQUEST_CODE);
我的阵列:
ArrayList<Piece> list = new ArrayList<Piece>();
ArrayList list=new ArrayList();
这是我的班级:
public class Piece implements Parcelable {
private String id;
private String name;
private int type;
private String text;
private String mp3;
public Piece (String id,String name,int type)
{
this.id=id;
this.name=name;
this.type=type;
}
public Piece(Piece ele)
{
this.id=ele.id;
this.name=ele.name;
this.type=ele.type;
this.text=ele.text;
}
public Piece (Parcel in)
{
id = in.readString ();
name = in.readString ();
type = in.readInt();
text= in.readString();
mp3=in.readString();
}
public static final Parcelable.Creator<Piece> CREATOR
= new Parcelable.Creator<Piece>()
{
public Piece createFromParcel(Parcel in)
{
return new Piece(in);
}
public Piece[] newArray (int size)
{
return new Piece[size];
}
};
public void makeText(String text)
{
this.text=text;
}
public void makeMp3(String mp3)
{
this.mp3= mp3;
}
public String getMp3()
{
return this.mp3;
}
public String getId()
{
return id;
}
public String getName()
{
return name;
}
public int getType()
{
return type;
}
public String getText()
{
return text;
}
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeString (id);
dest.writeString (name);
dest.writeInt(type);
dest.writeString (text);
dest.writeString (mp3);
}
}
public类片段实现了Parcelable{
私有字符串id;
私有字符串名称;
私有int型;
私有字符串文本;
私有字符串mp3;
公共片段(字符串id、字符串名称、int类型)
{
这个.id=id;
this.name=name;
this.type=type;
}
公共件(件ele)
{
this.id=ele.id;
this.name=ele.name;
this.type=ele.type;
this.text=ele.text;
}
公共物品(包裹内)
{
id=in.readString();
name=in.readString();
type=in.readInt();
text=in.readString();
mp3=in.readString();
}
公共静态最终包裹。创建者
=新的Parcelable.Creator()
{
公共件createFromParcel(地块中)
{
退回新件(在中);
}
公共片段[]新数组(整数大小)
{
退回新件[尺寸];
}
};
公共void生成文本(字符串文本)
{
this.text=文本;
}
公共void makeMp3(字符串mp3)
{
这个.mp3=mp3;
}
公共字符串getMp3()
{
归还这个.mp3;
}
公共字符串getId()
{
返回id;
}
公共字符串getName()
{
返回名称;
}
公共int getType()
{
返回类型;
}
公共字符串getText()
{
返回文本;
}
公共int描述内容(){
//TODO自动生成的方法存根
返回0;
}
公共无效写入包裹(包裹目的地,内部标志){
//TODO自动生成的方法存根
目的写入限制(id);
目的地记录(名称);
目的写入(类型);
目的地书面限制(文本);
目标写入限制(mp3);
}
}
我认为您不应该在这种情况下使用parcelable。我要么静态地访问数据(如果您只希望有一个数据的持久实例),要么使用缓存系统保存数据
这是一个公开的静态变量示例:
public static List<Piece> list;
公共静态列表;
它可以从应用程序中的任何地方访问,并且可以查看该类
然而,这样做非常混乱,被认为是一种不好的做法。或者,您可以创建一个对象,作为静态类或单例为您管理数据:
public class MyListManager {
private static List<Piece> mList;
public static List<Piece> getMyList() {
return mList;
}
public static void setList(List<Piece> list) {
mList = list;
}
}
公共类MyListManager{
私有静态列表;
公共静态列表getMyList(){
返回mList;
}
公共静态无效集合列表(列表){
mList=列表;
}
}
或者,您可以实施某种缓存系统来管理您的数据。我可以问一下您使用该包裹的目的吗?根据您使用数据的目的,我可能会为您提供解决方案。