The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.
This chapter will serve as a quick tour of the Android Studio IDE, to help you get settled in. Other Android-specific capabilities of Android Studio will be explored in the chapters that follow.
After the main editing area — where you will modify your Java source code, your resources, and so forth — the piece of Android Studio you will spend the most time with is the project explorer, usually available on the left side of the IDE window:
Figure 34: Android Studio Project Explorer, Showing Android Project View
This explorer pane has two main “project views” that an Android developer will use: the Android project view and the classic project view.
By default, when you create or import a project, you will wind up in the Android project view.
In theory, the Android project view is designed to simplify working with Android project files. In practice, it may do so, but only for some advanced developers. On the whole, it makes the IDE significantly more complicated for newcomers to Android, as it is rather difficult to see where things are and what relates to what.
We will return to the Android project view a bit later in the book and explain its benefits relative to resources and Gradle’s source sets.
However, for most of the book — most importantly, for the tutorials – we will use the classic project view.
To switch to the classic project view, click the pair of arrowheads to the right of the “Project Files” tab just above the tree in the explorer, and choose Project:
Figure 35: Android Studio Project Explorer, Showing Project View Drop-Down
On some machines, in some cases, the pair of arrowheads is instead a single drop-down arrowhead next to the currently-chosen view (e.g., Android).
Switching to the project view will change the contents of the tree to show you all of the files, in their associated directories:
Figure 36: Android Studio Project Explorer, Showing Classic Project View
This project view is much like its equivalent in other IDEs, allowing you to find all of the pieces of your Android project. We will be exploring what those pieces are, and how their files are organized in our projects, in the next chapter.
Right-clicking over a directory or file in the explorer will give you a context menu with a variety of options. Some of these will be typical of any sort of file manager, such as “cut”, “copy”, and/or “paste” options. Some of these will be organized according to how Android Studio manages application development, such as the “Refactor” sub-menu, where you can rename or move files around. Yet others will be specific to Android Studio, such as the ability to invoke wizards to create certain types of Android components or other Java classes.
Double-clicking on a file usually opens that file in a tab that allows you to edit that file, using some sort of editor.
Some file types, like images, can be opened but not edited, as Android Studio does not have editors for all file types.
Of course, as you change your app, you will want to try it out and see if it works, whether on a device or an emulator.
As noted in Tutorial #2, to run your project, just press the Run toolbar button:
Figure 37: Android Studio Run Controls, Showing Green Arrow to Run the App
You will then be presented with a dialog indicating where you want the app to run:
Figure 38: Android Studio Device Chooser Dialog
The “Connected Devices” category lists any devices or running emulators that the build tools can find. Some may be disabled due to compatibility issues, such as having an emulator for an old version of Android where your app requires a newer version of Android.
The “Available Emulators” category lists all AVDs that you have defined in the AVD Manager that are not already running. Again, you may find that some are disabled for compatibility reasons.
The “Create New Emulator” button brings up the wizard to create a new AVD, just like the one you can launch from the AVD Manager.
Next to the green “run” arrow button in the toolbar is a lightning bolt button. Sometimes, this will be grayed out and unusable. Other times, it will appear in yellow:
Figure 39: Android Studio Run Controls, With Instant Run Enabled
This button performs what is called “Instant Run”. Instead of building your app and pushing the app to the device or emulator, Instant Run attempts to patch your existing app based on whatever changes you made to the project since you last ran it.
On the plus side, Instant Run is very fast. However, the patched app is not exactly the same as would be your app built from scratch. Feel free to use this for smaller changes if you wish.
The preview of this section was lost in the sofa cushions.
The preview of this section will not appear here for a while, due to a time machine mishap.
The preview of this section was accidentally identified as an Android 'tasty treat' by the Cookie Monster.
The preview of this section apparently resembled a Pokémon.