Android Kotlin – Save activity’s state information

Screenshot 20181223 190341

To save additional information when your activity stops, then you have too override the onSaveInstanceState(). On Android Studio press Ctrl + O and start typing the method you want to override. There is an example that I put the score key-value pair to the Bundle override fun onSaveInstanceState(outState: Bundle?){ super.onSaveInstanceState(outState) outState.putInt(“SCORE”, score)} And here is some of the types you can put to Bundle. To retrieve the data you put to the Bundle then: override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) if (savedInstanceState != null) { score = savedInstanceState.getInt(“SCORE”, 0) } You…

Android Kotlin – Save activity’s state information Read More

Android Kotlin – Activity Lifecycle

Android Kotlin – Activity Lifecycle

Let’s start with the states: Initialized The starting state Created No focus and not visible Started No focus but visible Resumed Has focus and it is visible Destroyed It is destroyed and OS can removed it from memory Lifecycle callbacks onCreate It is called when the activity starts. Here you can initialize variables, inflate the layout file and everything else that needs to be executed only one time onStart It is called just before the activity becomes visible. Here you can add everything that needs to start before the activity…

Android Kotlin – Activity Lifecycle Read More