I\'ve successfully implemented onRetainNonConfigurationInstance() for my main Activity
to save and restore certain critical components across screen orientation
Easy with kotlin
@Parcelize
class MyState(val superSaveState: Parcelable?, val loading: Boolean) : View.BaseSavedState(superSaveState), Parcelable
class MyView : View {
var loading: Boolean = false
override fun onSaveInstanceState(): Parcelable? {
val superState = super.onSaveInstanceState()
return MyState(superState, loading)
}
override fun onRestoreInstanceState(state: Parcelable?) {
val myState = state as? MyState
super.onRestoreInstanceState(myState?.superSaveState)
loading = myState?.loading ?: false
//redraw
}
}