Lifecycle demo app
In this section, we will do a quick experiment that will help familiarize ourselves with the lifecycle methods our app uses as well as giving us a chance to play around with a bit more Java code.
Follow these steps to start a new project and then we can add some code:
- Start a new project.
- Choose the Basic Activity template.
- Call the project Lifecycle Demo. Of course, the code is in the download bundle in the Chapter 6 folder should you wish to refer to it or copy and paste it.
- Wait for Android Studio to generate the project files and then open the
MainActivity.java
file in the code editor.
You have created a new project with all the default settings. We will only need the MainActivity.java
file for this demonstration and will not be building a UI.
Coding the lifecycle demo app
In the MainActivity.java
file, find the onCreate
method and add these two lines of code just before the closing curly }
brace, which marks the end of the...