NewCharacterActivity.kt may already be open in an editor tab. If it is not, expand the app/src/main/java/com.bignerdranch.android.samodelkin directory and double-click NewCharacterActivity.kt.
The initial class definition appears in the editor:
class NewCharacterActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_new_character) } }
This code was generated along with your project. Notice that NewCharacterActivity, the activity you defined during the setup process, subclasses AppCompatActivity.
AppCompatActivity is part of the Android framework and serves as a base class for the NewCharacterActivity you will define in your app.
Also, notice that the onCreate function has been overridden. onCreate is an Android lifecycle function: a function that the Android operating system invokes for you when, in this case, your activity is initially created.
The onCreate function is where you retrieve view elements from the UI XML and where you wire up associated interactive logic for a particular activity. Take a look at its definition:
class NewCharacterActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_new_character)
}
}
Within onCreate, the setContentView function is called with the name of the XML file you defined, activity_new_character. setContentView takes a layout resource and inflates it – converting the XML to a UI view that is displayed on the phone, tablet, or emulator for a particular activity.