How to save and restore lambdas in Android?
问题 When implementing state restoration in Android, how can I save and restore a lambda? I tried saving it as Serializable and Parcelable, but it throws a compile error. Is there any way to save and restore them, or should I seek other approaches? 回答1: Kotlin lambdas implement Serializable , so they can't be saved like: override fun onSaveInstanceState(outState: Bundle) { outState.putSerializable("YOUR_TAG", myLambda as Serializable) super.onSaveInstanceState(outState) } Similarly, to restore