Last active
July 6, 2019 11:28
-
-
Save matthew-carroll/8cbb5bd52879abac00706069c738152a to your computer and use it in GitHub Desktop.
Implements onRestoreInstanceState in a custom View in Android.
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
@Override | |
public void onRestoreInstanceState(Parcelable state) { | |
// Cast the incoming Parcelable to our custom SavedState. We produced | |
// this Parcelable before, so we know what type it is. | |
SavedState savedState = (SavedState) state; | |
// Let our super class process state before we do because we should | |
// depend on our super class, we shouldn't imply that our super class | |
// might need to depend on us. | |
super.onRestoreInstanceState(savedState.getSuperState()); | |
// Grab our properties out of our SavedState. | |
this.name = savedState.name; | |
this.index = savedState.index; | |
// Update our visuals in whatever way we want, like... | |
requestLayout(); //...or... | |
invalidate(); //...or... | |
doSomethingCustom(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment