Created
February 18, 2015 20:08
-
-
Save slightfoot/736796d79b9b75199a7a to your computer and use it in GitHub Desktop.
Parcelable.ClassLoaderCreator example.
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 java.util.ArrayList; | |
| import android.os.Parcel; | |
| import android.os.Parcelable; | |
| public class TestParcel implements Parcelable | |
| { | |
| private ArrayList<String> mData; | |
| private int mValue; | |
| @SuppressWarnings("unchecked") | |
| protected TestParcel(Parcel in, ClassLoader loader) | |
| { | |
| mData = in.readArrayList(loader); | |
| mValue = in.readInt(); | |
| } | |
| @Override | |
| public void writeToParcel(Parcel dest, int flags) | |
| { | |
| dest.writeList(mData); | |
| dest.writeInt(mValue); | |
| } | |
| @Override | |
| public int describeContents() | |
| { | |
| return 0; | |
| } | |
| public static final Parcelable.ClassLoaderCreator<TestParcel> CREATOR | |
| = new Parcelable.ClassLoaderCreator<TestParcel>() | |
| { | |
| @Override | |
| public TestParcel createFromParcel(Parcel source) | |
| { | |
| return createFromParcel(source, null); | |
| } | |
| @Override | |
| public TestParcel createFromParcel(Parcel source, ClassLoader loader) | |
| { | |
| return new TestParcel(source, loader); | |
| } | |
| @Override | |
| public TestParcel[] newArray(int size) | |
| { | |
| return new TestParcel[size]; | |
| } | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment