Skip to content

Instantly share code, notes, and snippets.

@gfreivasc
Created April 6, 2019 17:56
Show Gist options
  • Save gfreivasc/412e9f5978bc76511248192de8cba6cc to your computer and use it in GitHub Desktop.
Save gfreivasc/412e9f5978bc76511248192de8cba6cc to your computer and use it in GitHub Desktop.
Second v
class MainActivity : ComponentActivity(R.layout.activity_main) {
private var count: Int = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
savedInstanceState?.let { state ->
count = state.getInt("COUNT", 0)
}
textView.text = "$count"
button.setOnClickListener {
count++
textView.text = "$count"
}
}
override fun onSaveInstanceState(outState: Bundle) {
outState.putInt("COUNT", count)
super.onSaveInstanceState(outState)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment