as_shortcuts_3

After hearing last minute about the Android Dev Summit last year, I was interested to see what topics they would cover and there was some great content.   As all of the talks were recorded I had a few on my list that I wanted to watch after the event but there was one I missed until I listened to one of the fragmented podcast episodes.  They highly recommended a talk called ‘Android Studio For Experts‘, which the podcast host Donn Felker said was an essential watch as they packed so many dev tips into the episode.

After watching it myself I thought it would be great to have a reference to the list of Android Studio shortcuts they talked so I put this blog post together. (not all tips are covered so watch the vid above for all of them).

I also thought it would be useful to include a few references to other resources I’ve found relating to Android Studio shortcuts which would help people complete their shortcut arsenal and become a AS ninja!

Intellij shortcut reference – official reference sheet for intellij
Developer Phil Android Studio Tips – great series of blog articles on Android studio shortcuts
Shortcut reminder plugin – great Android studio plugin which reminds you of shortcuts when you use their corresponding menu items (good while learning shortcuts).

General coding

Tab Auto Complete

as_tab_completion

Mac shortcut: Ctrl + Space …then Tab to select
Windows/Linux shortcut: Ctrl + Space …then Tab to select
When using the above shortcut to do auto complete, instead of hitting ENTER to select your auto complete entry, press TAB and the method/variable will be replaced instead of added to! (in example first autocomplete uses ‘Enter’ and second uses ‘Tab’)

Smart Auto Complete

wpid-wp-1453481271275.gif

Mac shortcut: Ctrl + Shift + Space (press once or twice)
Windows/Linux shortcut: Ctrl + Shift + Space (press once or twice)
Android Studio guesses auto complete based on context when holding down shift and pressing shortcut twice i.e. see in example how it uses the context passed in to method

Intention Actions

wpid-wp-1453481312850.gif

Mac shortcut: Alt + Enter
Windows/Linux shortcut: Alt + Enter
Depending on where the caret/cursor is a context sensitive menu will appear to give you some helpful action i.e. creating member variables in the constructor above

Extended Selection

extended_selection.gif

Mac shortcut: Alt + up/down
Windows/Linux shortcut: Ctrl+w/Ctrl+Shift+w

This shortcut allows you to select different sections of your code left to right and top to bottom by tapping the arrow key in that direction.

Suppress warning
Right click on the lint warning, press the arrow right on the keyboard and then select ‘suppress warning’

Live Templates

live_templates.gif

Mac shortcut: Command + j
Windows/Linux shortcut: Ctrl + j
Some handy examples for logging are;
logt – add tag constant with class name
logi – Log info
loge – Log error
logm – method with parameters
logr – method name and return value

You can also ‘Post fix’ the live templates to variables i.e. list.fori generates the following;
for (int i = 0; i < list.size(); i++) {

}

Filter Search

Filter searches are in multiple places in the Android Studio IDE menus (see example below).

filter_search.gif

Structural Replace
Ctrl + Shift + A and then type ‘Structural Replace’
Allows you to find elements of your code to replace that match a certain structure with variable names used to substitute the changing parts of the code i.e.

<code example fori>

Debugging

Analyze Stacktraceanalyze_stacktrace.png

Mac shortcut: Ctrl + Shift + A and type ‘Analyse Stacktrace’
Windows/Linux shortcut: Ctrl + Shift + A and type ‘Analyse Stacktrace’

This allows you to paste in a Stacktrace from a text file and it then converts it to show clickable links to the classes in your application.
Also you can check option to ‘Show changed in last x days’ which collects info on the version control commits in that time frame (if you have it configured) and if you press the button the generated Stacktrace ‘Show files modification info’ (second icon from bottom) it adds who committed those lines in the Stacktrace.

Testing

Create Test – Put cursor on class name you need to create test for and hit Alt + Enter (mac/win) and then select ‘Create Test’

as_create_test

Create Test Method – While in test class hit Alt + Insert (win) and Ctrl + Enter (mac) and select ‘Test Method’

as_create_test_method

Go to Test – When in a class hit Ctrl + Shift + T (win) and Command + Shift + T (mac) to navigate to a corresponding test class or create one. Press shortcut again while in test class to return to main Class.

as_goto_test

If you got this far an extra bonus is the shortcut to rule all shortcuts which is ‘Command Lookup’ which can be used to look up all other shortcuts/commands in Android Studio and was used a few times above (see screen at the very top of this blog post too);

Windows/Linux shortcut: Ctrl + Shift + A

Mac: Cmd + Shift + A

Thanks for reading and I hope these tips help you become a bit more efficient when developing using Android Studio!

 

P.S.  Just found another one so thought I’d just add a section here to capture any other cool ones I’ve missed!

Organize Imports ~> Ctrl + Alt + O

Goto Implementation (for example all implementations of an interface, works for methods and vars too) ~> Mac: Cmd+Shift+B,  Win/Linux : Ctrl+Alt+B