如果使用Pracelable传List 、List、List

import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;
import android.telecom.Call;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


public class SortByArtist implements Parcelable {

    private String singerName;

    private int songSize;

    private String albumName;

    private String filePath;

    private List<String> songNameList;

    private List<Long>  idList;

    private List<Long> albumIdList;

    private List<Bitmap> songCoverList;

    public SortByArtist(){

    }

    public SortByArtist(Parcel parcel) {
        parcel.readString();
        parcel.readInt();
        parcel.readString();
        parcel.readString();
        songNameList = new ArrayList<String>(); //刚开始没有new这些语句不行,报空指针,原来是要传参进去
        parcel.readList(songNameList, null);   //刚开始用parcel.readList(String.class.getClassLoader())也不行
        idList = new ArrayList<Long>();
        parcel.readList(idList, null);
        albumIdList = new ArrayList<Long>();
        parcel.readList(albumIdList, null);
        songCoverList = new ArrayList<Bitmap>();
        parcel.readList(songCoverList, null);
    }

    public String getFilePath() {
        return filePath;
    }

    public String getAlbumName() {
        return albumName;
    }
    public void setAlbumName(String albumName) {
        this.albumName = albumName;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public List<Long> getAlbumIdList() {
        return albumIdList;
    }

    public void setAlbumIdList(List<Long> albumIdList) {
        this.albumIdList = albumIdList;
    }

    public List<Long> getIdList() {
        return idList;
    }

    public void setIdList(List<Long> idList) {
        this.idList = idList;
    }

    public String getSingerName() {
        return singerName;
    }

    public int getSongSize() {
        return songSize;
    }

    public void setSingerName(String singerName) {
        this.singerName = singerName;
    }

    public void setSongSize(int songSize) {
        this.songSize = songSize;
    }

    public void setSongNameList(List<String> songNameList) {
        this.songNameList = songNameList;
    }

    public List<String> getSongNameList() {
        return songNameList;
    }

    public List<Bitmap> getSongCoverList() {
        return songCoverList;
    }

    public void setSongCoverList(List<Bitmap> songCoverList) {
        this.songCoverList = songCoverList;
    }

    @Override
    public String toString() {
        return "SortByArtist{" +
                "albumIdList=" + albumIdList +
                ", singerName='" + singerName + '\'' +
                ", songSize=" + songSize +
                ", SongNameList=" + songNameList +
                ", albumName='" + albumName + '\'' +
                ", filePath='" + filePath + '\'' +
                ", idList=" + idList +
                '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(this.singerName);
        parcel.writeInt(this.songSize);
        parcel.writeString(this.albumName);
        parcel.writeString(this.filePath);
        parcel.writeList(this.songNameList);   //刚开始用parcel.writeStringList(this.songNameList)报java.lang.RuntimeException: Parcel android.os.Parcel@445edcf8: Unmarshalling unknown type code 62260
        parcel.writeList(this.idList);
        parcel.writeList(this.albumIdList);
        parcel.writeList(this.songCoverList);
    }

    public static final Parcelable.Creator<SortByArtist> CREATOR = new Parcelable.Creator<SortByArtist>(){

        @Override
        public SortByArtist createFromParcel(Parcel parcel) {
            return new SortByArtist(parcel);
        }

        @Override
        public SortByArtist[] newArray(int i) {
            return new SortByArtist[i];
        }
    };
}

  

你可能感兴趣的:(如果使用Pracelable传List 、List、List)