android putParcelableArrayList putParcelable

import android.os.Parcel;
import android.os.Parcelable;

class VideoItem implements Parcelable {

long id;
String path;
String title;
String duration;
String folder;
String mimeType;
long size;

public VideoItem() {
// TODO Auto-generated constructor stub
}

public VideoItem(long id, String path, String title, String duration, String folder, String mimeType, long size) {
super();
this.id = id;
this.path = path;
this.title = title;
this.duration = duration;
this.folder = folder;
this.mimeType = mimeType;
this.size = size;
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getDuration() {
return duration;
}

public void setDuration(String duration) {
this.duration = duration;
}

public String getFolder() {
return folder;
}

public void setFolder(String folder) {
this.folder = folder;
}

public String getMimeType() {
return mimeType;
}

public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}

public long getSize() {
return size;
}

public void setSize(long size) {
this.size = size;
}

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

@Override
public VideoItem[] newArray(int size) {
return new VideoItem[size];
}

@Override
public VideoItem createFromParcel(Parcel source) {
VideoItem item = new VideoItem();
item.id = source.readLong();
item.path = source.readString();
item.title = source.readString();
item.duration = source.readString();
item.folder = source.readString();
item.mimeType = source.readString();
item.size = source.readLong();
return item;
}
};

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

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeString(path);
dest.writeString(title);
dest.writeString(duration);
dest.writeString(folder);
dest.writeString(mimeType);
dest.writeLong(size);
}
}

Note: CREATOR must be a static method

-----------------------------sent----------------------------------
Intent intent = new Intent(A.this, B.class);
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("videoitems", mFolderMap.get(mFolderList.get(position).folder));
intent.putExtras(bundle);
startActivity(intent);

---------------------------receive------------------------------
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
mBackTitle.setText(bundle.getString("title"));
mVideoItems = bundle.getParcelableArrayList("videoitems");
}

你可能感兴趣的:(android)