Creating the Fun Facts Project6:10 with Ben Deitch
In this video we'll walk through setting up a new app project in Android Studio. At last, we get to create something!
Need to import project files? All you do is select File -> Open from the Android Studio menu and then navigate to the FunFacts folder that you unzip from the project files. When you have that folder selected, click 'OK' and the project will be opened in a new Android Studio window.
If you have any capital letters in your package name you'll get this error when building your app:
Before we start any work I want to stress one very important thing, 0:00 don't be afraid to make mistakes with this stuff. 0:05 You can learn so much about programming from making mistakes and then fixing them. 0:07 You can always undo things and if you really mess up, you can 0:12 download the project files for each video or even start over from scratch. 0:15 Check the teacher's notes for a link about how to import project files, and 0:20 again, we're here to help. 0:23 Head over to the community with any questions or problems. 0:25 All right, we're ready to start programming, 0:29 let's get started with our Fun Facts app. 0:32 We're going to approach this as an iterative process, and we'll 0:34 start with a very simple version that simply displays one fun fact all the time. 0:37 It won't be very useful or fun yet, but it will introduce us to the tools we'll use, 0:43 as well as verify that everything is working correctly on our computers. 0:48 All right, with Android Studio open, 0:52 let's select Start a new Android Studio project from the top of the list. 0:55 We're going to start with the application name which is the name of our app. 0:59 Let's type Fun Facts with two capital letter Fs and a space in between. 1:03 We want this to look exactly how we want it to appear on the device or 1:09 on the Google Play Store. 1:13 Also the application name can only consist of letters, numbers, spaces, 1:14 or underscores. 1:19 Next we have the company domain, which is where you can put your own name or 1:21 the organization you work for. 1:25 I'll leave mine as teamtreehouse.com, but feel free to use your own. 1:27 Notice that the package name matches the company name and 1:31 the application name, it changes based on what we type. 1:35 Although we can go over here and click on Edit if we want to change it ourselves. 1:39 Just don't add any capital letters to your package name, that's asking for trouble. 1:44 The package name is important because it's used to differentiate our app 1:49 from others on the Play Store. 1:52 If there's another Fun Facts app on the Play Store with the same name, 1:54 then we need something besides just the application name to tell them apart. 1:58 The package name is what makes them unique, 2:02 the application name gets appended to the package name so 2:04 that apps by the same organization can be grouped together by a common package name. 2:08 So all Team Treehouse apps will start with com.teamtreehouse. 2:13 We can change the package name later on if we need to, but it's kind of a hassle, so 2:18 it's best to get it right here at the start. 2:23 We especially don't want to change it after we publish our app, the package name 2:25 must be exactly the same in order to make any updates to an existing app. 2:29 Down here is the project location on your computer, 2:34 I'll leave mine as is but feel free to change this, then click Next. 2:37 Now we need to pick devices and version of Android that our app can run on. 2:44 This can be a little overwhelming at first, but let's keep it simple and 2:49 leave phone and tablet checked. 2:53 We'll be writing this app to work on a phone and it will also work on tablets, 2:55 but we aren't going to optimize how it looks on tablets. 2:59 Now we need to pick the minimum SDK, which stands for software development kit. 3:02 The Android SDK and 3:07 API levels are often used interchangeably, there's a one to one relationship. 3:09 Meaning each version of the SDK has a corresponding API level, 3:14 also we've got a helpful message here. 3:18 Lower API levels target more devices but have fewer features available. 3:21 Okay, but what does this mean? 3:26 Let's click on the Help me choose button to find out. 3:27 This brings up a graph showing the distribution of Android versions 3:31 out in the wild, and what this shows us is that 97.4% 3:35 of devices are on Android 4.0 or above. 3:39 That corresponds to API level 15, so 3:43 we can feel fairly safe in picking API level 15 for our app. 3:47 Another nice thing about not using the lowest API level is that we don't need to 3:51 make any additional changes to make our app backwards compatible. 3:55 Okay, but what about the very latest version of Android? 3:59 Well, we are targeting API 15 and 4:02 up, which means that our app should run on each release as it comes out. 4:05 The API level really only comes into play 4:10 when we're using features that either lose support or are brand new. 4:12 The Fun Facts app focuses on the basics though, so this isn't an issue. 4:16 The big difference for us is that Android will apply some basic visual modifications 4:21 based on which SDK version the app is using. 4:25 All right, let's hit OK to leave this screen, 4:28 then make sure API 15 is selected and hit Next. 4:31 On this screen, we see a list of pre-built activities that we can chose from. 4:37 In Android, 4:41 activities can be thought of as the different screens that make up an app. 4:42 Starting from an already built activity can definitely make building an app 4:46 a little easier. 4:49 But since we're still learning, we'll use the fourth option, the Empty Activity. 4:51 Let's select that and click Next, and now we want to pick a name for our activity. 4:56 Typically, we'll want something like MainActivity for the main activity in 5:03 the app, or a name that describes what the activity is or does. 5:07 Since we're showing fun facts, let's name our's FunFactsActivity. 5:11 Notice that as we change the name, the layout name changes as well, cool. 5:19 Now we can finish and Android Studio will take a minute to build our project, and 5:24 after a short delay, we should have everything ready to go. 5:29 You'll notice that Android Studio by default shows the tip of the day. 5:40 You can choose to not see tips if you want, but I recommend leaving the tips on 5:45 because you can learn helpful keyboard shortcuts or other useful information. 5:49 I'll close that to get it out of the way. 5:53 And what we have here is a project shell that's pretty much ready to run, 5:59 it's a full fledged app, albeit a very boring one. 6:03 In a moment we'll come back and run it to make sure everything is working. 6:06
You need to sign up for Treehouse in order to download course files.Sign up