Nov 16, 2015
5 minutes to read
The first tool we are going to discuss is arguably the most important: the IDE (Integrated Development Environment). It’s definitely the tool where developers are going to spend most of their time.
Android Studio was announced two years ago, during the 2013 edition of Google I/O and has since become the de facto standard. It is based on JetBrains’ IntelliJ IDEA Java IDE and, on top of that, Google added its own modules (most of which end up in IntelliJ anyway). Most importantly, Android Studio introduced the new build chain for Android, based on Gradle (which will be the topic of our next blogpost).
Despite its features, everyone has not adopted Android Studio when it came out. For starters, it did not include support for the NDK (Native Development Kit). Also, up till December 2014 (and Android Studio 1.0), Google kept offering the previous solution (Eclipse + ADT) as the first available choice on its developper website . But now, there is no longer any reason not to use Android Studio.
Now let’s jump to the core of the matter: how we use Android Studio. Let’s start by going through some of the most interesting but unknown features offered by Android Studio.
First, if you want updates as soon as they are available, you can choose to leave the Stable Channel for releases and opt for a more frequently updated one. All the channels (including the Canary one) have proven surprisingly stable so far, and features can takes weeks or even months before reaching the Stable Channel. You can modify this in the Preferences through this path: Appearance & Behavior > System Settings > Updates.
The most important feature provided by Android Studio is probably the static analysis for Java code, Android code or even XML files. This static analysis goes very deep into potential problems and is able of some quite powerful analysis. Studio provides a lot of information about possible issues on the fly, but there are many inspections that require a manual start. This can be done via Analyze > Inspect Code. You can also modify the severity of each inspection (Error, Warn, Info,…) in the Preferences (Editor > Inspections).
A feature it seems a lot of people don’t know about (definitely not used enough in presentations and conferences) is that Android Studio provides a presentation mode: bigger fonts, fullscreen display, removal of surrounding Tool Windows, etc. This can be triggered via View > Enter Presentation Mode. Good news is you can still use all your keyboard shortcuts and live templates (see below) and everything Android Studio provides you in your regular developing environment.
Still on the matter of showing your code, Android Studio (and IntelliJ) recently introduced rich-text copy: this allows you to copy your code while conserving your font, and (more importantly) your syntaxic coloring. You can also specify a different theme for your rich-text copy than the one of your editor (allowing you for example to have a dark background in your IDE and make slides with a white background). This is very useful if you want to share a code snippet through email, bug reporting, instant messaging,…
Android Studio provides a ton of keyboard shortcuts, some of which make a big difference when you spend a lot of time inside your IDE. For example, there are a ton of available shortcuts for navigation (⌘O to Open a Class, ⌘⇧O to Open a File, ⌘⌥O to Open a Symbol, ⇧⇧ for Search Everywhere, ⌘E for Recent files). One of the most important shortcuts to remember is the Find Action shortcut (⌘⇧A), which allows you to access all actions available in Android Studio. You also have lots of shortcuts to provide information about the code around you (^J for Quick Documentation, ⌘P for Parameters Info, ⌘Y for Quick Definition).
Studio also provides you with a lot of ways of generating code, so you don’t have to write it yourself. Of course, you should strive for code reusability, but sometimes, it just would not make sense to factorize it, even though the code is quite similar (for example, the code for creating Intents). Basic autocompletion already works great (and you also have access to a smarter, type-aware autocompletion, default keymap: ^⇧Space) but you can also generate code like constructors, getters and setters, etc. via the Generate action (default keymap: ⌘N). You can also insert templates (default keymap: ⌘J). Just enter the name of the template in the code and, at validation, it will be replaced by the concerned template. Studio provides a few by default, but you can create your own, or reuse some created by others.
Also of note is the Surround With action (default keymap: ⌘⌥T) which allows you to surround your code with blocks like if, for, try/catch, etc.
Still on the matter of reusing code, Google introduced Code Samples in Android Studio last year. Those are mini-projects that demonstrate how to perform a lot of basic (or less basic) actions on Android (like interacting with Bluetooth or NFC, using the Camera2 API, notifications, animations,…). This is especially useful when learning about new systems, like Android TV, Google Fit, Android Wear,…
A more unusual (but most welcome) feature is Language Injection (⌥⏎). This allows you to edit the content of a String with the IDE being aware of the syntax (for example, it works with SQL, HTML, CSS,…). Thus you get all the features from your IDE, like autocompletion. Very useful if you are writing a lot of SQL for a Content Provider.
Finally, Android Studio also provides a Productivity Guide (accessible through: Help > Productivity Guide). This tells you about all the productivity tips and tricks Studio provides and how frequently (or recently) you have used them. This can help you by telling you about functionalities you were not aware of (and therefore, never used).
There is a lot Android Studio has to offer, and this blog post offered an insight into some of the most useful features (at least according to us), but barely scratches the surface of everything available.
Finally, since it makes sense for us to all be working on the same settings (coding style, default keymaps, templates, …), we compiled a version of settings that we encourage every newcomer to use (and then customize them if he feels like it, after familiarizing itself with the IDE). You can access them at this link (warning, these settings will override your settings):