Skip to content

Instantly share code, notes, and snippets.

@kostovtd
Created April 23, 2017 09:46
Show Gist options
  • Save kostovtd/d76e5f36abfd36d407a1f99d424a7cb3 to your computer and use it in GitHub Desktop.
Save kostovtd/d76e5f36abfd36d407a1f99d424a7cb3 to your computer and use it in GitHub Desktop.
A Person POJO with Parcelable interface.
import android.os.Parcel;
import android.os.Parcelable;
public class Person implements Parcelable {
private String firstName;
private String lastName;
private int age;
public Person(String firstName, String lastName, int age) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.firstName);
dest.writeString(this.lastName);
dest.writeInt(this.age);
}
protected Person(Parcel in) {
this.firstName = in.readString();
this.lastName = in.readString();
this.age = in.readInt();
}
public static final Parcelable.Creator<Person> CREATOR = new Parcelable.Creator<Person>() {
@Override
public Person createFromParcel(Parcel source) {
return new Person(source);
}
@Override
public Person[] newArray(int size) {
return new Person[size];
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment