Android Quick Tips #6 — Android Studio

After looking at various Android Quick Tips, this week we'll look at a few more of our favorite productivity tips for Android Studio.

Android Quick Tips #1 Series Overview

Shortcuts, Shortcuts, Shortcuts

Shortcuts are the single most important "hack" for developer productivity. Your development time is valuable, and often, when you're in the flow, your fingers struggle to keep up with your thoughts. Knowing shortcuts is a neat way to increase the chance that your flow isn't interrupted and your thoughts can focus on the software development process and not the typing.

Since Android Studio is based on Intellij, and shares the same shortcuts, we recommend to print the IntelliJ Reference Card (Win/Lin, Mac OS) and put it right in front of you. Whenever you need a mental break, take a quick look at your new cheat sheet and learn a new shortcut.

Forcing Yourself to Use Shortcuts

A different approach is to have an independent party observe your IDE usage and let you know when you didn't use a shortcut. There is an amazing plugin for that: Key promoter. You can install it directly from any IntelliJ IDE, like Android Studio, from Preferences -> Plugins -> Browse repositories -> Key promoter.

Key promoter Popup

Key promoter will show a little popup when you missed using a shortcut. The dialog is not the prettiest, but that might be by design...

Our Favorite: Live Templates with Ctrl + J or ⌘ + J

Our favorite shortcut is the usage of ⌘ + J. It offers "Live templates", which depending on your context, will fill in boilerplate code for you. For example, when you're in a method in an Activity or Fragment, you could hit ⌘ + J, type "toast" and hit enter. It'll create the following code for you and set your cursor at the right position:

Toast.makeText( YourActivity.this, "", Toast.LENGTH_SHORT ).show();  

Once you hit ⌘ + J you can scroll through the list of available live templates at that context. We recommend to go through that list at least once to make yourself familar, what code you've been writing manually for no reason.

Another example is if you're in a Fragment class, you could hit ⌘ + J, select the newInstance template and it'll create this code for you:

public static YourFragment newInstance() {  
    Bundle args = new Bundle();

    YourFragment fragment = new YourFragment();
    fragment.setArguments( args );
    return fragment;
}

Live templates are insanely useful. Make sure to know them!

What are your favorite shortcuts? Let us know in the comments.

Explore the Library

Find interesting tutorials and solutions for your problems.