Skip to content

Instantly share code, notes, and snippets.

@myungpyo
Created January 4, 2022 04:58
Show Gist options
  • Save myungpyo/01ac3f4d7fa97218436269fe0b9b618d to your computer and use it in GitHub Desktop.
Save myungpyo/01ac3f4d7fa97218436269fe0b9b618d to your computer and use it in GitHub Desktop.
package io.github.myungpyo.simplekspsample.sample
import android.os.Bundle
class MainActivityStateBinding {
fun save(stateHolder: MainActivity, stateStore: Bundle) {
with(stateHolder) {
stateStore.putString("StickyState_stringProp", stateHolder.stringProp)
stateStore.putInt("StickyState_intProp", stateHolder.intProp)
}
}
fun restore(stateHolder: MainActivity, stateStore: Bundle?) {
stateStore ?: return
stateHolder.stringProp = stateStore.getString("StickyState_stringProp") ?: stateHolder.stringProp
stateHolder.intProp = stateStore.getInt("StickyState_intProp")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment