Hello and welcome. In this lesson, you will learn how to code the main activity file. In our last lesson, we looked at the Android Manifest which is right here. We learned how to change some important attributes in our app such as labels and colors. But now we're gonna look at our main activity file. So here's our main activity file in our Java folder. Let's open it and I'm going to go to My Application. And here's the main activity file. Click on that. First, what is the main activity file? A lot of programming languages have a main function that starts or opens the program. Android apps have a main activity file that is designated as the activity to be launched when the user taps on the app icon. The main activity file serves a similar purpose as the main function that we used in the beginning series. It's where the app starts and it controls the main logic. So Android uses information that is found in the manifest file that we did earlier. And within the manifest file we have this main activity and then it does some setups within the activity file. So let's take a look at the main activity file. Everything in this file is just code. There's nothing actually to look at visually because there's no layout functionality. To see things on your phone or your tablet you must have a layout file. Now we'll learn about the layout in the next video, but for now just think of the layout file as doing the exact same thing the console did in our beginning series. In the beginner series in our hello world program we said print line hello world. And the console printed hello world. But the layout is much more sophisticated than a console. So let's look at the main activity file which is a KT file. So we have all this code here, but what is this stuff? Now remember in our intelliJIDE we created hello world program. It was basically two lines of code that we could easily understand because it said print hello world. That's easy. There is nothing like that here. All of this code you see here is generated automatically by a build greater process. It's a lot of stuff in this program, but no reference to hello world. So let's go through it so I can show you how it works. I'm going to go through it line by line because this file is important. It's the main logic and you will have to code through all of this stuff. So let's understand the first line. So the primary class is called main activity and then there's a colon. And then we have what's called the app compact activity. So what does all this mean? Well it means that our main activity class extends from the app compact activity class. So what does this extension mean? That means that the main activity has everything that the app compact activity has plus some more stuff. The app compact activity class is a subclass of an activity class or a broader class. The app compact activity class supports all modern Android features. So to make our app available to the largest number of devices and the largest number of possible users we have to use the app comp activity class. That's what it does. So we're always going to expand from the app compact activity class because that has all the functionality we need in order to communicate with all of the Android setups. So the main activity extends from there giving it more functionality. Okay, after the class definition the first thing we want to do is override this function called on create. On create means that when a user clicks the icon to open up your app then this on create command takes over. On create is part of an app lifecycle command. And I'll explain life cycles in a later lesson, but for now just know that on create is done only once at the start of your app. So what does it mean to override? Well, when you override a function essentially what you're doing is you're replacing or adding to the code that's already there. So we have two options. We can completely replace the function or you can extend the function. So what we're doing in this case is we're going to extend the function. And we do that with this command, super. To be a super of something it's just something greater than the old thing. You still have the basic stuff plus some extra stuff. It's supercharged. So that means that whatever we were doing in the on create function, whatever it was doing, it's going to continue to do the same thing, but we're going to add our own code right here. Okay, so what are we going to add? We're going to add this one. This is the important one right here. This line of code is actually saying that we're going to set the content view to all of this stuff our layout activity main. This is actually our command. And what is that going to do? It's going to view what is ever in this art layout dot activity main file. So let's look at this. Let's start with the R. R means Rez. Rez means resource. This is a resource file. So I'm going to open it up. Now within the Rez directory is a thing called layout and that's right here. There's four of them, but we're going to look at the layout file right now. So I'll open that up. And lo and behold, what do we have? We have the activity main and that's right here. This command is actually calling this file right here. So I'm going to open that. And there it is. It's within our layout. This is what the Android phone layout looks like. So this thing is actually going to write to our phone whatever it is that we want to say our program will put it right here. And right now it says hello world. That's where our text is. This layout is the same thing as our console. So this process within the main activity calls the layout file and that process is called layout inflation. It's a process which the views that we define in our layout file are turned or inflated into kotlin objects. And all of those objects become. And right now we have a text object of hello world. So we can make that bigger so you can see it. Now in the layout file I can modify this to anything that you want. It's like our print line. Okay, so you've seen the main activity. So that concludes our lesson on coding the main activity. So thanks for watching. Stay tuned for the next lesson. So let's go.