The Project window gives you access to your project's files and directories. By default it only shows the assets that developers work with regularly, but you can see everything on your disk by changing from the Android scope to the Project scope. There are many other scopes available that let you quickly navigate coding problems, to-do comments, and see your files organized for production or testing.
- [Instructor] Android Studio's user interface is built around windows. One of the most important is the project window, where you have access to all of your project's files and folders. For this demonstration, you can continue with the previous project, or open any other Android project. The project window appears by default on the left side of your screen. You can open and close it by clicking on the project tab on the left, or you can go down to the lower left corner, just move the mouse down there, and when the context menu pops up, you can choose project from there.
You can also get to your windows by going to the menu and choosing view, tool windows, and then selecting the window from that list. Or, you can use the associated keyboard shortcut. Hold down the command key on Mac, or the alt key on Windows, and then press the appropriate number. On Mac, that would be command one. So, when I press command one, that opens and closes the project window. The project window's views are known as scopes.
The scope list is available when you pull down the list. If you see tabs instead of a pull down list, click the gear icon and select group tabs. That list will then appear. I've described the default scope named Android, which presents a filtered view of the files and folders that programmers tend to use on a daily basis, and I've also shown you the project scope, which shows the actual file and folder organization on your hard disk. There are some other scopes that you might find useful, though.
This is the packages scope. It gives you a simple way of looking at your Java files and resources organized by Java Package, or for resources by folder. If I open up my base package, I see a combination of all the Java class files from all of the different locations in the project, including main activity, which is actually a part of my app, and generated classes, such as the R class. And you'll also see testing classes, like application test and example unit test.
The scratches view lets you manage temporary files where you can toss a bit of random code until you need it. So, for example, lets say I wanted to save a bit of code that I'm not going to need in the current class, but I might want to hold on to for later on. So, I'll copy this bit of code, then I'll go to the menu and choose tools, new scratch file. If you don't see new scratch file on the tools menu, you can instead right click in the scratches scope in the project window and select new and then file.
And then, because I already copied the code into the clipboard, it appears in the new scratch file. And then I'll close the new scratch file. I'll go back to my project window, switch to Android, and then switch back to scratches, and I see a new folder appear. And there's the file. So, notice that I didn't have to figure out where to put the file. That's all handled automatically for me by Android Studio, and I also don't need to do a number of manual operations like pasting the code into place.
Just copy the code, and create the scratch file, and then it'll be there later on when you need it. When you're done with your scratch files, you can just delete them from within the scratches scope. Press the delete key, and confirm. The problem scope only shows files that need attention. It's a great way of working through the bugs in your application. I'll go back to my main activity class, and I'll just remove a required semicolon, and instantly something shows up in the problem scope over on the left.
Now, I'll close the main activity class, and then I'll drill down to the file that has the problem, and double click, and the file is opened. Then, to get to the problem, I'll press the F2 key, which is the same on Mac and Windows. The cursor goes to the location of the problem. I'll expand the code, and then move the cursor to the line that has the problem. Then, I'll put the semicolon back in, and the problem indicator disappears on the left. The production scope, again, shows Java and resource files, but it also includes generated files.
It's called production because these files are required during the packaging process. So, this gives you an easy view of all the files that might be used as the app is compiled and packaged for distribution. The test scope shows you your Java classes that include J unit tests. I'll drill down to the test slash Java directory, and open this class file, example unit test, and it implements a simple test to see whether a bit of math is correct.
I'll right click on the class and choose run example unit test. Now, this is a pure Java test. It doesn't have anything in the test that would require an Android device. And so, it goes in that test scope, but there's another scope called Android instrumentation tests, and this shows testing classes that run on Android virtual or physical devices. The sample that's provided with Android Studio projects isn't that useful, but you can learn a lot about using these kinds of tests at the URL that's placed in the comment.
So, that's a tour of the project window. You can manage your files in a number of different ways in this window, and you can also work through your bugs and manage temporary scratch files. By default, you'll be looking at everything in the Android scope, but you can use whichever of these scopes you find useful.
- Installing Android Studio on Mac and Windows
- Creating Android Studio projects
- Setting up the development environment, including HAXM and the new Android emulator
- Importing existing code into Android Studio projects
- Exploring the interface, including the editor and project windows
- Managing project builds and dependencies
- Creating new Java classes
- Refactoring code
- Using templates
- Using breakpoints and watch expressions
- Updating apps with Instant Run
- Using Git for version control
Skill Level Beginner
Q: This course was updated on 04/27/2017. What changed?
A: New videos were added that highlight the new features introduced in Android Studio 2.3. In addition, the following topic was updated: update apps with Instant Run.