Skip to content

Instantly share code, notes, and snippets.

@mattleibow
Created October 25, 2014 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattleibow/a1c0d058965056f06b98 to your computer and use it in GitHub Desktop.
Save mattleibow/a1c0d058965056f06b98 to your computer and use it in GitHub Desktop.
base for saving android view state
// state that this view preserves
public class BaseInstanceState : Android.Views.View.BaseSavedState
{
// create a new state to be saved
public BaseInstanceState(IParcelable superState)
: base (superState)
{
}
// read the values out of the parcel
public BaseInstanceState(Parcel parcel)
: base (parcel)
{
ReadFromParcel (parcel);
}
// read the values out of the parcel
public virtual void ReadFromParcel (Parcel source)
{
}
// write the values into the parcel
public override void WriteToParcel (Parcel dest, ParcelableWriteFlags flags)
{
base.WriteToParcel (dest, flags);
}
// create the field that is used by Android
[ExportField("CREATOR")]
private static InstanceStateCreator InitializeCreator()
{
return new InstanceStateCreator ();
}
private class InstanceStateCreator : Java.Lang.Object, IParcelableCreator
{
public Java.Lang.Object CreateFromParcel (Parcel source)
{
return new BaseInstanceState (source);
}
public Java.Lang.Object[] NewArray (int size)
{
return new BaseInstanceState[size];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment