1 00:00:00,079 --> 00:00:02,662 (upbeat music) 2 00:00:05,242 --> 00:00:06,917 Now one thing that can confuse people 3 00:00:06,917 --> 00:00:09,415 new to Android Studio are the templates that 4 00:00:09,415 --> 00:00:11,755 Google include with it. 5 00:00:11,755 --> 00:00:13,997 Especially as they sometimes change them 6 00:00:13,997 --> 00:00:15,996 when they release a new version. 7 00:00:15,996 --> 00:00:17,819 Now I try to keep the course up-to-date, 8 00:00:17,819 --> 00:00:19,796 but with new versions of Android Studio 9 00:00:19,796 --> 00:00:21,266 coming out every few months, 10 00:00:21,266 --> 00:00:23,964 there will be times when it looks that little bit different 11 00:00:23,964 --> 00:00:26,136 to how it appears in these videos. 12 00:00:26,136 --> 00:00:27,663 So I'm going to create a couple of new projects 13 00:00:27,663 --> 00:00:29,942 using some of the templates that are currently 14 00:00:29,942 --> 00:00:31,772 shipping with Android Studio, 15 00:00:31,772 --> 00:00:33,213 and show off some of the ways 16 00:00:33,213 --> 00:00:34,689 that they differ from each other. 17 00:00:34,689 --> 00:00:36,370 Now remember that these are just templates though. 18 00:00:36,370 --> 00:00:38,282 They're provided to save you having to type in 19 00:00:38,282 --> 00:00:41,207 some of the basic code that projects need, 20 00:00:41,207 --> 00:00:43,359 but there's no reason why you can't change 21 00:00:43,359 --> 00:00:45,562 any of the code that the templates create. 22 00:00:45,562 --> 00:00:47,796 If you use a template that includes a menu, 23 00:00:47,796 --> 00:00:49,622 for example, but decide that you don't want to 24 00:00:49,622 --> 00:00:50,905 provide a menu in your project, 25 00:00:50,905 --> 00:00:53,583 then you can just delete the menu code. 26 00:00:53,583 --> 00:00:55,450 And if you've used a word processing programme 27 00:00:55,450 --> 00:00:58,589 such as Libre Office or Microsoft Word, 28 00:00:58,589 --> 00:01:00,940 then you may be familiar with the concept of templates, 29 00:01:00,940 --> 00:01:03,484 and these are really no different. 30 00:01:03,484 --> 00:01:05,272 Alright, so let's have a look at the templates, 31 00:01:05,272 --> 00:01:07,883 and I'm gonna start by creating a new project. 32 00:01:07,883 --> 00:01:10,593 Now if you're watching this video in the Kotlin course 33 00:01:10,593 --> 00:01:13,687 make sure that the include Kotlin support box is ticked. 34 00:01:13,687 --> 00:01:18,038 That's the default, and probably already will be ticked. 35 00:01:18,038 --> 00:01:19,460 So I'm gonna start off anyway, click on 36 00:01:19,460 --> 00:01:21,641 Start a new Android Studio project. 37 00:01:21,641 --> 00:01:23,149 And we can this button that I'm talking about 38 00:01:23,149 --> 00:01:24,937 down here, include Kotlin support. 39 00:01:24,937 --> 00:01:27,773 So again, that's the default, it probably is already clicked 40 00:01:27,773 --> 00:01:29,460 and if you're in the Kotlin course, 41 00:01:29,460 --> 00:01:31,519 make sure that is clicked, but if you're watching 42 00:01:31,519 --> 00:01:33,532 this video in the Java course, 43 00:01:33,532 --> 00:01:35,445 you need to un-tick that box. 44 00:01:35,445 --> 00:01:37,019 Leaving it ticked will cause Android Studio to 45 00:01:37,019 --> 00:01:40,204 generate Kotlin, rather than Java code. 46 00:01:40,204 --> 00:01:42,477 Now I'll mention that each time we create a new project, 47 00:01:42,477 --> 00:01:44,546 at least for the first few projects, 48 00:01:44,546 --> 00:01:46,650 so that you generate the correct code 49 00:01:46,650 --> 00:01:48,990 for the language you're using. 50 00:01:48,990 --> 00:01:52,072 Now I'm going to un-tick the box, that's because Java 51 00:01:52,072 --> 00:01:54,480 programmers don't need to know anything about Kotlin, 52 00:01:54,480 --> 00:01:56,123 but Kotlin programmers will need 53 00:01:56,123 --> 00:01:58,372 basic familiarity with Java. 54 00:01:58,372 --> 00:02:00,724 So whenever our video shows code in both courses, 55 00:02:00,724 --> 00:02:02,986 I'm going to show the Java code. 56 00:02:02,986 --> 00:02:05,611 Don't worry though, if we need to write any code at all, 57 00:02:05,611 --> 00:02:07,789 there'll be separate videos for each course. 58 00:02:07,789 --> 00:02:10,939 So in the Kotlin course, keep that box ticked, 59 00:02:10,939 --> 00:02:12,762 then you can compare the Kotlin code on your screen 60 00:02:12,762 --> 00:02:16,531 with the Java code that's going to appear on mine. 61 00:02:16,531 --> 00:02:18,333 So leave everything else on this screen, 62 00:02:18,333 --> 00:02:19,716 as I said, for this particular application, 63 00:02:19,716 --> 00:02:21,189 I'm doing something a little bit different 64 00:02:21,189 --> 00:02:23,619 and I'm including, and I've unchecked the box 65 00:02:23,619 --> 00:02:26,062 and I'm gonna click on Next. 66 00:02:26,062 --> 00:02:28,254 I'm gonna leave everything else as it is, 67 00:02:28,254 --> 00:02:30,212 and on this next screen we're going to leave 68 00:02:30,212 --> 00:02:32,338 everything else as it is, as well. 69 00:02:32,338 --> 00:02:34,138 Now we're going to be explaining these screens 70 00:02:34,138 --> 00:02:35,465 in the next video, but for now, 71 00:02:35,465 --> 00:02:37,052 I just want to focus on the templates, 72 00:02:37,052 --> 00:02:38,573 so I'm gonna click on Next. 73 00:02:38,573 --> 00:02:39,999 Now at the time I'm recording this, 74 00:02:39,999 --> 00:02:43,707 Android Studio ships with 13 templates, 75 00:02:43,707 --> 00:02:45,332 and the images on this selection screen try to 76 00:02:45,332 --> 00:02:48,741 give an indication of what they contain. 77 00:02:48,741 --> 00:02:51,435 Now, Add No Activity, this one here, 78 00:02:51,435 --> 00:02:53,466 is the most basic, but I generally don't use 79 00:02:53,466 --> 00:02:55,435 that for most apps because we normally need 80 00:02:55,435 --> 00:02:56,953 at least one activity. 81 00:02:56,953 --> 00:02:58,956 Now I'm not gonna go through describing all the templates, 82 00:02:58,956 --> 00:03:01,192 because a lot of the explanation won't make 83 00:03:01,192 --> 00:03:02,736 much sense just yet anyway. 84 00:03:02,736 --> 00:03:04,784 And, in fact, you may be wondering what this activity 85 00:03:04,784 --> 00:03:05,740 that I've just mentioned is. 86 00:03:05,740 --> 00:03:08,093 But don't worry, I'll be explaining all that next. 87 00:03:08,093 --> 00:03:10,545 Now, once you're comfortable, with Android Studio 88 00:03:10,545 --> 00:03:12,908 and you've worked through a few of the apps in this course, 89 00:03:12,908 --> 00:03:14,830 by all means, have a go at creating projects 90 00:03:14,830 --> 00:03:16,360 based on each of these templates 91 00:03:16,360 --> 00:03:18,432 to get a feel for what they provide. 92 00:03:18,432 --> 00:03:20,590 For now the only ones we really need to use 93 00:03:20,590 --> 00:03:24,675 are the Basic Activity and the Empty Activity. 94 00:03:24,675 --> 00:03:26,345 So Basic and Empty. 95 00:03:26,345 --> 00:03:29,079 Now, you can see from these images that Basic Activity 96 00:03:29,079 --> 00:03:31,981 contains a little bit more than the Empty Activity template. 97 00:03:31,981 --> 00:03:34,772 You can see the icon for the drop-down menu at the top right 98 00:03:34,772 --> 00:03:37,528 and it also has a floating action button, 99 00:03:37,528 --> 00:03:40,487 this little yellow button, at the bottom right. 100 00:03:40,487 --> 00:03:41,698 So, if your app will include a menu 101 00:03:41,698 --> 00:03:43,768 or floating action button or both, 102 00:03:43,768 --> 00:03:45,861 then you'd probably be best off starting 103 00:03:45,861 --> 00:03:47,931 with the Basic Activity template. 104 00:03:47,931 --> 00:03:49,247 But if you don't want either of those, 105 00:03:49,247 --> 00:03:52,026 the use the Empty Activity template instead. 106 00:03:52,026 --> 00:03:53,150 But what if you want a menu 107 00:03:53,150 --> 00:03:54,658 but not a floating action button? 108 00:03:54,658 --> 00:03:56,117 Well in that case, you can either start 109 00:03:56,117 --> 00:03:58,743 with an Empty Activity and add the menu code, 110 00:03:58,743 --> 00:04:02,601 or, and this is probably easier, start with a Basic Activity 111 00:04:02,601 --> 00:04:05,582 and delete the code for the floating action button. 112 00:04:05,582 --> 00:04:07,664 So I'm gonna start by choosing this Empty Activity 113 00:04:07,664 --> 00:04:09,891 over here, so we can see what that provides. 114 00:04:09,891 --> 00:04:11,804 Now on the next screen as I click that, 115 00:04:11,804 --> 00:04:14,357 I'm going to leave everything as it is 116 00:04:14,357 --> 00:04:16,337 and accept the default values. 117 00:04:16,337 --> 00:04:18,564 So we'll see this Activity Name and Layout Name 118 00:04:18,564 --> 00:04:20,072 used in a minute, so just remember that they're called 119 00:04:20,072 --> 00:04:24,958 MainActivity and activity_main and click on Finish. 120 00:04:24,958 --> 00:04:26,249 Now Android Studio takes a little while 121 00:04:26,249 --> 00:04:29,631 to create the project, then you should end up with something 122 00:04:29,631 --> 00:04:31,053 that will look a little bit like this, 123 00:04:31,053 --> 00:04:32,999 once this has finished. 124 00:04:32,999 --> 00:04:36,184 So I'll just fast forward this. 125 00:04:36,184 --> 00:04:37,456 Alright so you should end up seeing 126 00:04:37,456 --> 00:04:39,703 something that looks a little bit similar to this. 127 00:04:39,703 --> 00:04:41,628 Now, the version of Android Studio that I'm using 128 00:04:41,628 --> 00:04:43,563 to record this video, starts off in what's called 129 00:04:43,563 --> 00:04:47,016 Android View, after creating a new project. 130 00:04:47,016 --> 00:04:49,256 And you can see this Android tab up here, 131 00:04:49,256 --> 00:04:50,493 in the top left hand corner, 132 00:04:50,493 --> 00:04:53,643 and Android was the default mode that's been selected. 133 00:04:53,643 --> 00:04:56,208 Now some people prefer to work in Project View, 134 00:04:56,208 --> 00:04:58,886 but it really doesn't matter which one you use. 135 00:04:58,886 --> 00:05:03,628 We can switch to Project View, by clicking Project. 136 00:05:03,628 --> 00:05:07,302 And then we can expand this selection of folders 137 00:05:07,302 --> 00:05:09,810 and expand the details out of our application. 138 00:05:09,810 --> 00:05:11,284 Now some of the other views won't show 139 00:05:11,284 --> 00:05:12,814 most of the files we need, 140 00:05:12,814 --> 00:05:15,041 so I won't be using them in this course. 141 00:05:15,041 --> 00:05:18,337 Now, the app that we've created is called MyApplication, 142 00:05:18,337 --> 00:05:20,475 well it's actually called MyApplication2 and that's because 143 00:05:20,475 --> 00:05:23,323 I already created one previously called MyApplication, 144 00:05:23,323 --> 00:05:25,406 and I expanded that view and you saw that we saw 145 00:05:25,406 --> 00:05:29,189 there was this app folder, expand that, click that open. 146 00:05:29,189 --> 00:05:30,981 And this is where most of the files 147 00:05:30,981 --> 00:05:32,501 we're interested in are located. 148 00:05:32,501 --> 00:05:36,518 Now in Android View, if we switch back to that, 149 00:05:36,518 --> 00:05:38,205 the app folder is at the top level, 150 00:05:38,205 --> 00:05:40,051 this one here, and I can expand that out. 151 00:05:40,051 --> 00:05:43,009 And this is why many people prefer to work in that view. 152 00:05:43,009 --> 00:05:45,985 More files are visible in Project View, but most of them 153 00:05:45,985 --> 00:05:48,533 are the ones that you don't generally need to worry about. 154 00:05:48,533 --> 00:05:50,570 The main files we have to change or create, 155 00:05:50,570 --> 00:05:53,482 are in this java, or res folders, 156 00:05:53,482 --> 00:05:57,069 or if we switch back to Project View, 157 00:05:57,069 --> 00:06:00,177 we can expand that out and we've still got the src, 158 00:06:00,177 --> 00:06:03,271 main, and we've got the java and res folders here, 159 00:06:03,271 --> 00:06:04,857 they're just a little bit, 160 00:06:04,857 --> 00:06:07,197 in a slightly different location when in Project View 161 00:06:07,197 --> 00:06:09,493 compared to Android View. 162 00:06:09,493 --> 00:06:11,069 So it's the same set of files essentially, 163 00:06:11,069 --> 00:06:12,924 just presented in a different way. 164 00:06:12,924 --> 00:06:15,512 So choose whichever view you're most comfortable with, 165 00:06:15,512 --> 00:06:18,560 I'll be mainly using the Android View in this course. 166 00:06:18,560 --> 00:06:20,721 Now, over on the right hand pane, up here, 167 00:06:20,721 --> 00:06:22,060 there's two files open, 168 00:06:22,060 --> 00:06:25,393 activity_main.xml and MainActivity.java. 169 00:06:26,357 --> 00:06:28,529 Now these are the names of the Activity and the Layout 170 00:06:28,529 --> 00:06:30,452 from the earlier screen. 171 00:06:30,452 --> 00:06:33,523 Now, if we close these, we can open them up 172 00:06:33,523 --> 00:06:35,560 by just opening the particular folder, 173 00:06:35,560 --> 00:06:37,720 in the case of the java folder, we can double click 174 00:06:37,720 --> 00:06:41,545 MainActivity to open them up, and the activity_main 175 00:06:41,545 --> 00:06:43,560 we can look in the layout folder, and double click that 176 00:06:43,560 --> 00:06:45,461 and open it up like that. 177 00:06:45,461 --> 00:06:47,283 And again, going back to Android View, 178 00:06:47,283 --> 00:06:49,457 we can see essentially the same thing. 179 00:06:49,457 --> 00:06:52,671 Opening up we can see that our MainActivity file is there, 180 00:06:52,671 --> 00:06:55,000 then in the res folder, in the layout folder, 181 00:06:55,000 --> 00:06:58,116 there's our activity_main.xml. 182 00:06:58,116 --> 00:07:00,997 Now the activity_main.xml, defines what 183 00:07:00,997 --> 00:07:03,967 the screen for the activity will look like, 184 00:07:03,967 --> 00:07:06,003 and if I go into this Design tab, 185 00:07:06,003 --> 00:07:08,028 which is selected currently anyway, 186 00:07:08,028 --> 00:07:10,323 you can see that it looks very similar 187 00:07:10,323 --> 00:07:11,954 to the template image. 188 00:07:11,954 --> 00:07:14,339 There's no menu icon showing and no floating action button, 189 00:07:14,339 --> 00:07:17,186 just the text Hello World, as you can see there. 190 00:07:17,186 --> 00:07:20,043 Now MainActivity also doesn't contain very much, 191 00:07:20,043 --> 00:07:21,138 if we have a look at that. 192 00:07:21,138 --> 00:07:23,182 Don't worry about what any of this code means at the moment, 193 00:07:23,182 --> 00:07:24,971 I'm just showing you what the templates look like 194 00:07:24,971 --> 00:07:27,233 so you don't get stuck when Google changes them again 195 00:07:27,233 --> 00:07:28,638 in the future. 196 00:07:28,638 --> 00:07:30,473 And also, don't worry that this is Java code, 197 00:07:30,473 --> 00:07:32,588 if you're watching this in the Kotlin version of the course, 198 00:07:32,588 --> 00:07:35,165 anything we do with the screen layouts is the same, 199 00:07:35,165 --> 00:07:38,345 regardless of the language used, so some of the videos 200 00:07:38,345 --> 00:07:40,383 are the same for both courses. 201 00:07:40,383 --> 00:07:42,546 Now we can see that we've got a class here called 202 00:07:42,546 --> 00:07:45,779 MainActivity and that's got a single method called OnCreate. 203 00:07:45,779 --> 00:07:47,781 So class name, method name. 204 00:07:47,781 --> 00:07:49,644 Make a mental note of that, and then we'll see 205 00:07:49,644 --> 00:07:51,324 how the next template differs. 206 00:07:51,324 --> 00:07:52,664 So what I'm gonna do now though, 207 00:07:52,664 --> 00:07:54,755 is end the video and in the next video 208 00:07:54,755 --> 00:07:57,005 we'll go ahead and we'll create a second project, 209 00:07:57,005 --> 00:08:00,384 this time based on the Basic Activity template. 210 00:08:00,384 --> 00:08:01,689 So I'll see you in the next video.