Android Studio productivity tips: Part1

As a developer, the better you understand your tools, the more productive you get.

In the series, I’m going to cover some essential and helpful tips and tricks based on our daily usage scenarios, to help you to get the most out of Android Studio.

__swag-practice [_-Project-AndroidProject-practice-__swag-practice] - ...-app-src-main-java-com-enginebai-sw-data-Repository.java [app] - Android Studio_015

Key concept: Mouseless-Driven Developement

An over-dependence on using your mouse while coding can have results of being lower productivity. That is why that we emphasize the Mouseless-Drive Development. Try to use the keyboard shortcut as much as possible can help you be more productive. The keyboard shortcuts in this article are based on default keymaps on MacOS. Linux and Windows equivalents can be found here. And I use the following symbols to represent key.

  • ⌘ = Command Key
  • ⌥ = Option (Alt) Key
  • ⇧ = Shift Key
  • ⌃ = Control Key

Navigation

During the time we develop a great Android app, we may spend more time nagivating in our code than you can image, so I choose Navigation as the first topic in this series. Let’s get started to learn how to navigate code efficiently.

Search Everywhere: Double ⇧Shift

The most wild and powerful search from your entire project. If you don’t have any idea how to find the thing you want, just type double SHIFT to search everywhere.

search everywhere
Search Everywhere

Navigate -> File (or Class, Symbol)

The Shortcut keys for Navigate -> File / Class / Symbo are [⌘ + ⇧ + O] / [⌘ + O] / [⌘ + ⌥ + O] respeatively. You can browse any file in your project, such Java file, xml layout, drawable, string resource file…etc. Or if you know that is a class or symbol in advance, please use Navigate -> Class / Symbol.

navigate file

navigate symbol

File structure: ⌘ + F12

Use Navigate -> File Structures.This will list all the constants, instance / static variables, methods, inner classes…etc in the file. I usually use this to jump to a specific methods in a class file.

file structure
** Small tips: After opening file structure, you can jump to specific method right away just typing the name in the window, the window will highlight the results matching the name you type.

Go to Line: ⌘ + L

When opening a file, you can go to a exact line by Navigate -> Line/Column.

go to line

Recent Files: ⌘ + E

I often copy / check code / do some stuff from other file, after performing whatever I do, how can I go back to the original file right away? Use View -> Recent FIles.

recent file

recent file 2
** Small tips: you can keep moving the cursor in the recent file list by keeping use Recent Files shortcut key, no need to press up and down key.

Call Hierarchy: ⌥ + ⌃ + H

How do I find all the caller of a specific method? Use Navigate -> Call Hierarchy. You can find the whole calling path from the start of the method.

call hierarchy

Type Hierarchy: ⌃ + H

How do I find the class inheritance hierarchy? How can I find which classes extends another class and vice versa? Or how can I find which classes implement this interface? Use Nagivate -> Type Hierarchy.

type hierarchy
Fine the children class of Message class.

Find Usages: ⌥ + F7

How do I find where/who uses a field / method / class / file? Use Edit -> Find -> Find Usages. The result will be shown grouped by value read and write.

find usage

find usage2
Move mouse cursor to the field you’d like to search, then press ⌥ + F7

Find in Paths: ⌘ + ⇧ + F

The alternative way to find usages is Find in Paths with more powerful searching. Use Edit -> Find -> Fine in Paths. You can specify where to search, how to match your keyword.

find in path

Android Studio supports different search modes:

  • Match case: The search is cast-sensitive.
  • Words: The search results must match the whole word only (and case-sensitive).
  • Regex: The search term will be perceived as a regular expression.
  • File mask: You can specify the file matching pattern, such as*.kt for searching kotlin source code files.
find in path2
You also can choose where to find, i.e. find in /app module only.

In the next article, we will take a look at some useful tips when we write the code.

Happy coding!!

9 thoughts on “Android Studio productivity tips: Part1

Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑