The lifecycle demo app
In this section, we will do a quick experiment that will help to familiarize us with the lifecycle functions that our app uses and give us a chance to play around with a bit more Kotlin code.
Follow these steps to start a new project and then we can add some code:
Start a new project and choose the Basic Activity project template; this is because during this project, we will also look at the functions that control the app menu and the Empty Activity option doesn't generate a menu.
Call it Lifecycle Demo. The code is in the download bundle in the
Chapter06/Lifecycle Demo
folder, should you wish to refer to it or copy and paste it.Keep the other settings as they have been in all our example apps so far.
Wait for Android Studio to generate the project files and then open the
MainActivity.kt
file in the code editor (if it is not opened for you by default) by left-clicking on the MainActivity tab above the editor.
We will only need the MainActivity.kt
file for this demonstration...