Android Studio Tutorial Part 3 2019 Edition

hey welcome back everybody we're gonna pick up where we left off in the last video so in the last video we created this screen here and then act and and an Android it's called an activity but we have this activity here and it has a button but right now the button doesn't do anything so whenever I hit it it doesn't do anything what we did do is we set up something in the logcat we have our log statement there so we can go to logcat and see it says button was pressed so if i go back to the emulator you'll see every time i hit it hit the button adds a new record there so that's all cool but we want it but we want to make it go to a new screen so as soon as you hit that it'll go to a new screen will pop up so let's go ahead and get started so if let's go ahead and go to the left open up projects there I then select Android then what we're gonna do is and if it looks all closed like that you can just double click on app Java then there'll be three come files inside of here go ahead and click on the first one and then when I set up this project I set it up as example but whatever is there just open up main activity so here's our main activity now go up one level so the package that it's in sign up and right click and go to new then there are all kinds of stuff you can add you can add graphics you can add images you can add all kinds of stuff all we want to do is Kotlin file class and I'll call this one we'll call this about me and it can be anything here but about me is a good name I'm gonna go ahead and select class and hit OK and you're not gonna see that screen but that's okay so here's our new class so you'll notice now we have two classes we have main activity there which has a bunch of code in there and then we have about me so what we need to do is we need to tell this about me class and it's identified by class but we need to tell this class that this is a new screen so what we can do is we can do so what we could do is we can do go right after there and do that a colon and do app compat activity and you'll notice as soon as you start to type that it's kind of like autocomplete and it pops up there and all you have to do is hit enter and it fills the rest of now we need those kind of brackets and activity is now working just fine well not quite yet but this is our new class so we have a class called about me and it's gonna say hey this about me class is basically going to be a new screen so remember a new screen is a an act it's called an activity in android so here we go so I'm gonna do come down here and I'm gonna make some space and I'm gonna do I think it's control ensure on Mac and that you can type and use there's another number of methods there so see there's a keyboard shortcut for over right there so that's all oh I think right all oh no what was it I don't usually use this keyboard shortcut that's why I don't do it but anyway or there's another way to get to it you can just start typing on creates because that's the one that we want so yes so there's many ways to add methods here you can just you can do it on Mac it's ctrl enter and then you can click on overrides and this pops up a little box and you can start typing on create and it selects it for you so if I sit on crate now it adds a little bit of code for us or there's another way you can just put your mouse there or click there and start typing on creates and you'll see that there's we want this one right here so I'll go ahead and hit on that so here's our this is basically saying on create is called every time it's called every time the screen comes on or every time that this activity comes to the screen so if I go back to the emulator right now we're on we're on that i duplicate main activity I must have done something wrong don't know why that's there anyway so so this main activity here whenever we're on this screen here it means hey we're on this main activity so let's go ahead and go back to about me and here we go so now we're gonna add a new layout and we'll do this put your mouse co-chair my house just after the super dot on crate and typeset content view and you'll see it automatically selects this for you so go ahead and hit the first one but this one we need to type something type r dot layout dot will call this act about me there we go so you'll notice there's some red text here and that means that sin that's an error so it says unresolved reference activity about me so just click on there once and do option and sure on a Mac I think it's all tin or on a Windows and we'll have some options here to fix this so what can we do to fix this let's go ahead and do the first option create new crate layout resource file so I'm gonna do that and it pops up this this pops up this this dialog I'm gonna go ahead and everything is just fine right there hit OK and it pops up this new activity about me XML so let's go back to about me and this should get rid of all the errors so now you'll notice that it doesn't have the red icons or does it have the red lines underneath there that means it's fixed so um there's one more couple more things we need to do so to set this activity up let's go ahead and if we put our mouse over here you'll see there's an error so we're not an error but this there's just a suggestion for us so what we need to do is click on it once and do option enter or alt enter on a Mac I think and select add activity to manifest manifest is a file kind of like a manifest as a file that that keeps track of all the screens in the app we can actually open it up here so if we open up there here's an Android activity or heiser here's our Android manifest and this is kind of like where we put all our all our screens so if you look through this we can see we have one activity called main activity and another activity called about me but you don't really need to look at this screen it just does it automatically okay so if we go back to the emulator you'll notice hey we cut the button now but it doesn't do anything so let's go back to main activity and inside of this big button dot said onclicklistener because this is going to be called anytime somebody clicks on the button let's go to the end here and let's do start activity there are a lot of options but let's go ahead and select the first one here that has intense so go ahead and click on that and then we'll do type intents I then put that and then put this it's not important here so go ahead and do option and sure to import that actually no let's not do that yet so tight yeah so I didn't follow along intense and then hit enter it automatically imports that I then do just the opening parenthesis and do this I then do about me class Java so I'm gonna go ahead and save that so it's basically gonna say hey whenever you there's the big button whenever somebody clicks on it do all of that so first log something to the console down there which you saw in the last video the next one is start a new activity and intent is kind of what we need that's just the code you need to write so start activity is gonna start about me okay so cuz I'm gonna save it now I'm gonna go ahead and run it and go back to the emulator and let's see what happens so give it a second to build that says Gradle build running down there and there's some progress bar here this usually takes a couple of I mean it could take up to a minute I guess it's going kind of slow it usually takes only like ten or fifteen seconds for whatever reason it's taking a little bit longer and here we go now it says the stalling APK so it's installing it on the app there and here we go so here's our screen now let's go I'm gonna go ahead and click on button don't see what happens so it pulled up a new screen but the reason it's all blank the reason this is all blank is because if you go to about me and if we come in so hold down the command key or ctrl key I think on Windows and click on activity and it opens up activity about me and you'll see this is blank so let's do something else let's grab a button and let's put a button and let's put a button in the top right so I'm gonna click there then to constrain it click drag let go click drag let go and I'm gonna go ahead and save that out then let's go ahead and go and run it again and this should work so we should have a button in the top left for the main activity so it's installing apk now so here's a button on the top left and as soon as I click on it it opens up the new screen and the new screen has a button on the top right so that's what we're clearly going from content main there to activity about me so hopefully you'll learn something I'm gonna see I'm gonna try to make one or two more videos today hopefully you learn something about creating a new activity going from main activity to about me if you have any questions leave them in the comments and I'll try to respond but yeah just leave a comment I know I'm kind of busy but leave a comment and I'll try to I'll try to respond Thanks

Loading