I'm doing a simple game to learn how to program for Android with Kotlin. I am afraid of an activity (game) of the game and when you find a number it takes you to another atcivity (Finish), passing two information, that are in OnCreate.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val iFinish = getIntent()
val numbers: String = iFinish.getStringExtra("LEVEL_NUMBER")
val plays: String = iFinish.getStringExtra("NUMBER_PLAYS")
textViewNumPlays.text = plays
textViewRandom.text = numbers
}
Then I have two buttons, one that returns for the Main Menu, another restarts the game with the same previous configurations, but the one that restarts needs the val numbers and the function is out of the onCreate.
fun onButtonRestartClicked (view: View){
val message1 = numbers.toString()
val iRestart = Intent(this, GameActivity::class.java).apply {
putExtra("EXTRA_MESSAGE", message1);
}
if (iRestart.resolveActivity(packageManager) != null) {
startActivity(iRestart)
}
}
My question is how to load this val numbers into a function outside the onCreate?