Domanda

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.

È stato utile?

Soluzione

Given byte[] AlbumArt, you are probably exceeding the 1MB IPC limit.

Any ideas as on how to overcome this solution and pass the ArrayList in an Intent.

I'd start by getting rid of AlbumArt. Images should be in an image cache, one designed to make sure that you do not run out of heap space by having a maximum size and getting rid of least-recently-used entries (or moving them to a second-tier disk cache). As a side benefit, moving the byte[] out of the Parcelable will probably clear up your problem.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top