Skip to content

Instantly share code, notes, and snippets.



Created Nov 5, 2013
What would you like to do?
The Bundle holds Key<String> Value<Parcelable> pairs and provides convenience methods for several of the primitive wrapper types such as Short, Byte, Integer, etc. In the event your data does not easily fit into one of these methods, you can implement the Parcelable interface and use Bundle.putParcelable(key,value).
import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
import java.util.List;
* POJO to hold contents of a Mail. Implements Parcelable so that it can be used in the bundle to
* save and restore information to the UI entered by the user in a Activity.
public class Mail implements Parcelable {
private String mFrom;
private String mTo;
private String mSubject;
private String mBody;
public Mail(String from, String to, String subject, String body) {
mFrom = from == null ? "" : from;
mTo = to == null ? "" : to;
mSubject = subject == null ? "" : subject;
mBody = body == null ? "" : body;
public String getFrom() {
return mFrom;
public String getTo() {
return mTo;
public String getSubject() {
return mSubject;
public String getBody() {
return mBody;
public int describeContents() {
return 0;
public void writeToParcel(Parcel dest, int flags) {
List<String> values = new ArrayList<String>();
public static final Creator<Mail> CREATOR = new Creator<Mail>() {
public Mail createFromParcel(Parcel source) {
List<String> values = new ArrayList<String>();
return new Mail(values.get(0), values.get(1), values.get(2), values.get(3));
public Mail[] newArray(int size) {
return new Mail[size];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment