1lateinitvar textView: TextView
23// some transient state for the activity instance4var gameState: String?=null56overridefunonCreate(savedInstanceState: Bundle?){7// call the super class onCreate to complete the creation of activity like8// the view hierarchy9super.onCreate(savedInstanceState)1011// recovering the instance state12 gameState = savedInstanceState?.getString(GAME_STATE_KEY)1314// set the user interface layout for this activity15// the layout file is defined in the project res/layout/main_activity.xml file16setContentView(R.layout.main_activity)1718// initialize member TextView so we can manipulate it later19 textView =findViewById(R.id.text_view)20}2122// This callback is called only when there is a saved instance that is previously saved by using23// onSaveInstanceState(). We restore some state in onCreate(), while we can optionally restore24// other state here, possibly usable after onStart() has completed.25// The savedInstanceState Bundle is same as the one used in onCreate().26overridefunonRestoreInstanceState(savedInstanceState: Bundle?){27 textView.text = savedInstanceState?.getString(TEXT_VIEW_KEY)28}2930// invoked when the activity may be temporarily destroyed, save the instance state here31overridefunonSaveInstanceState(outState: Bundle?){32 outState?.run{33putString(GAME_STATE_KEY, gameState)34putString(TEXT_VIEW_KEY, textView.text.toString())35}36// call superclass to save any view hierarchy37super.onSaveInstanceState(outState)38}