Last active
September 11, 2018 07:48
-
-
Save nasrabadiAM/7d4321b9b4ce0b2ab49d13bc92d7a056 to your computer and use it in GitHub Desktop.
This file contains 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 ParcelablePerson implements Parcelable { | |
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { | |
public ParcelablePerson createFromParcel(Parcel in) { | |
return new ParcelablePerson(in); | |
} | |
public ParcelablePerson[] newArray(int size) { | |
return new ParcelablePerson[size]; | |
} | |
}; | |
private static final long serialVersionUID = 1L; | |
private int age; | |
private String name; | |
//getters & setters | |
// Parcelling part | |
public ParcelablePerson(Parcel in){ | |
this.id = in.readLong(); | |
this.name = in.readString(); | |
this.age = in.readInt(); | |
} | |
@Override | |
public int describeContents() { | |
return 0; | |
} | |
@Override | |
public void writeToParcel(Parcel dest, int flags) { | |
dest.writeLong(this.id); | |
dest.writeString(this.name); | |
dest.writeInt(this.age); | |
} | |
@Override | |
public String toString() { | |
return "ParcelablePerson{" + | |
"id='" + id + '\'' + | |
", name='" + name + '\'' + | |
", age='" + age + '\'' + | |
'}'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment