I'm developing a Media Player Application where I'm using ArrayList
to store the list of songs, and want to use that same list between a Service
and other Activities
. I've written a custom type Songs implementing Parcelable
Interface. This is how I did it:
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];
}
};
Now the Problem is I'm getting FAILED BINDER TRANSACTION
when I try to pass the Arraylist<Songs>
in an Intent. As a workaround I'm using static variables. Any ideas as on how to overcome this solution and pass the ArrayList<Songs>
in an Intent.