我想在 2 个片段之间传递数据。我传递的数据是 SongDetails 类的对象。这是传递数据的片段的代码
ArrayList<SongDetails> Songinfo =new........;
if (Songinfo.size()>0)//Songinfo is an object of the class SongDetails..
{
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("Fragdata",Songinfo);
dv.setArguments(bundle);
}
接收数据的代码
Bundle bundle=this.getArguments();
final ArrayList<SongDetails> Songinfo =bundle.getParcelableArrayList("Fragdata");
当我运行它时,应用程序崩溃了......我做错了什么?
SongDetails 的代码
package sourcecode.jazzplayer;
import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;
public class SongDetails implements Parcelable {
Bitmap icon;
String song;
String Artist;
String Album;
String Path;
int time;
int icLauncher;
public SongDetails() {
}
public SongDetails(Parcel in) {
String[] data = new String[4];
in.readStringArray(data);
this.Path = data[0];
this.song= data[1];
this.Album= data[2];
this.Artist = data[3];
}
public String getSong() {
return song;
}
public void setSong(String song) {
this.song = song;
}
public String getArtist() {
return Artist;
}
public void setArtist(String Artist) {
this.Artist = Artist;
}
public Bitmap getIcon() {
return icon;
}
public void setIcon(Bitmap bitmap) {
this.icon = bitmap;
}
public String getPath2() {
return Path;
}
public void setPath2(String Path) {
this.Path = Path;
}
public String getAlbum() {
return Album;
}
public void setAlbum(String Album) {
this.Album = Album;
}
public void setIcon(int icLauncher) {
this.icLauncher = icLauncher;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeStringArray(new String[] { this.Path,this.song,this.Album,this.Artist });
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public SongDetails createFromParcel(Parcel in) {
return new SongDetails(in);
}
public SongDetails[] newArray(int size) {
return new SongDetails[size];
}
};
}