#Kotlin# You must override onSaveInstanceState and onRestoreInstanceState to store and retrieve your variables you want to be persistent
###Life cycle graph
Life cycle graph
Store variables
public override fun onSaveInstanceState(savedInstanceState: Bundle) { super.onSaveInstanceState(savedInstanceState) // prepare variables here savedInstanceState.putInt("kInt", 10) savedInstanceState.putBoolean("kBool", true) savedInstanceState.putDouble("kDouble", 4.5) savedInstanceState.putString("kString", "Hello Kotlin") } ###Retrieve variables
public override fun onRestoreInstanceState(savedInstanceState: Bundle) { super.onRestoreInstanceState(savedInstanceState) val myInt = savedInstanceState.getInt("kInt") val myBoolean = savedInstanceState.getBoolean("kBool") val myDouble = savedInstanceState.getDouble("kDouble") val myString = savedInstanceState.getString("kString") // use variables here }