Created
April 23, 2017 09:46
-
-
Save kostovtd/d76e5f36abfd36d407a1f99d424a7cb3 to your computer and use it in GitHub Desktop.
A Person POJO with Parcelable interface.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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