【发布时间】:2014-02-18 11:43:11
【问题描述】:
我正在开发一个媒体播放器应用程序,我使用ArrayList 来存储歌曲列表,并希望在Service 和其他Activities 之间使用相同的列表。我编写了一个自定义类型 Songs 实现Parcelable 接口。我就是这样做的:
String ID, Title, Artist, Album, Genre, Duration, Path;
byte[] AlbumArt;
//constructors go here
//getters and setters go here
public Songs(Parcel in) {
readFromParcel(in);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeString(this.ID);
dest.writeString(this.Title);
dest.writeString(this.Artist);
dest.writeString(this.Album);
dest.writeString(this.Genre);
dest.writeString(this.Duration);
dest.writeByteArray(this.AlbumArt);
dest.writeString(this.Path);
}
private void readFromParcel(Parcel in) {
this.ID = in.readString();
this.Title = in.readString();
this.Artist = in.readString();
this.Album = in.readString();
this.Genre = in.readString();
this.Duration = in.readString();
in.readByteArray(this.AlbumArt);
this.Path = in.readString();
}
public static final Parcelable.Creator<Songs> CREATOR = new Parcelable.Creator<Songs>() {
@Override
public Songs createFromParcel(Parcel source) {
// TODO Auto-generated method stub
return new Songs(source); // using parcelable constructor
}
@Override
public Songs[] newArray(int size) {
// TODO Auto-generated method stub
return new Songs[size];
}
};
现在的问题是,当我尝试在 Intent 中传递 Arraylist<Songs> 时,我得到了 FAILED BINDER TRANSACTION。作为一种解决方法,我正在使用静态变量。关于如何克服此解决方案并在 Intent 中传递 ArrayList<Songs> 的任何想法。
【问题讨论】:
标签: java android arraylist parcelable