Skip to content

Instantly share code, notes, and snippets.

@matthew-carroll
Created July 6, 2019 11:14
Show Gist options
  • Save matthew-carroll/16aaa4aedd5b7c5db49143e1cb1cc67c to your computer and use it in GitHub Desktop.
Save matthew-carroll/16aaa4aedd5b7c5db49143e1cb1cc67c to your computer and use it in GitHub Desktop.
Implements Parcelable in a custom View in Android (4/4).
public class MyView extends View {
private static class SavedState extends BaseSavedState {
String name;
int index;
SavedState(Parcelable superState) {
super(superState);
}
private SavedState(Parcel in) {
super(in);
name = in.readString();
index = in.readInt();
}
@Override
public void writeToParcel(Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeString(name);
out.writeInt(index);
}
public static final Parcelable.Creator<SavedState> CREATOR
= new Parcelable.Creator<SavedState>() {
public SavedState createFromParcel(Parcel in) {
return new SavedState(in);
}
public SavedState[] newArray(int size) {
return new SavedState[size];
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment