Mastering Android Studio (2023)— Part 2: Teleporting

Alireza Akbari
7 min readSep 6, 2023

--

Image from gamerant.com

In the previous part, we covered some essential shortcuts that are crucial to know (which you can refer to, before continuing with this article). Now, in this part, we’re taking productivity to the next level by exploring the power of teleportation to quickly navigate to the desired locations in code. So, without further ado, let’s dive right into our beloved Android Studio and uncover these time-saving gems!

6- Teleporting (Navigating)

In addition to the previously mentioned shortcuts like ⇧⌘O and ⇧⇧, which are great for finding and navigating to specific places, let’s dive deeper into the world of teleportation within Android Studio.

  1. + 0..9 (Open Related Window): Take a look at the image below to discover how these shortcuts can open some of the most useful windows. For example, you can quickly access the Logcat by pressing ⌘6 or opening the Project Window with ⌘1. Give it a try and experience the seamless navigation firsthand.
Look at the other shortcuts that Android Studio is providing as well

These shortcuts provide a convenient way to access frequently used windows directly, saving you valuable time and clicks. Experiment with them to find the ones that best suit your workflow and boost your productivity within Android Studio.

2- ⌘B (Go to Declaration or Usage): It’s a well-known shortcut that you’re probably using frequently. Simply navigate between the usage and its declaration.

Go to Usage <- -> Declaration Navigation

3- ⌥⌘B (Go to Implementation): Abstraction is a key to developing clean codes, having interface and abstraction class are crucial, but ⌘B won’t help you in such a situation when you want to find the implementation (Concrete class) instead of the declaration (interface/abstraction class). Consider the following code as an example:

// interface
interface DataSource {
fun fetchUser(): User
fun updateUser(name: String)
}

// implementation
class FakeDataSourceImpl : DataSource {
override fun fetchUser(): User = User("Fake User")

override fun updateUser(name: String) = println("update fake user")
}

// usage
class Repository(private val dataSource: DataSource) {
fun fetchUser() = dataSource.fetchUser()
}

When you’re in Repository class and you’re deciding to navigate to the fetchUser() implementation, there is no straightforward way by default, using ⌘B shortcut navigates you into the interface instead of FakeDataSourceImpl , So you can use ⌥⌘B to find and navigate to both the declaration and all implementations.

Take a look at the difference between ⌘B and ⌥⌘B

4- ⌥F7 (Find File Usage): Finding a file usage is useful especially when you’re looking for the usage of an XML file or an XML attribute or entity (e.g. id of a view in layouts, a string of strings.xml, a color from colors.xml and so on).

⌘B navigates to the resource declaration, but not vice versa!

Remember this shortcut is not that smart, in the demonstration below, you can see it’s listing useless files as well (Congratulations!! the keystroke color is changed from now on!).

Listing Android resource files and Resource declarations are not usually useful.

5- ⌥F1 (Locate File in Project Explorer): You’re surfing the project files by looking at their implementations or declarations, You may feel lost after some moments when you finally find the thing you were looking for (Of course there could be simpler situations when you’ll find this shortcut helpful). Now by pressing ⌥F1 you can locate the current file in the Project Explorer window.

You can change the Project Explorer viewer too, as you can see we moved from Project Viewer to Android Viewer.

6- ⌘⌥← or → (Move Caret Backward or Forward by History): You can use this shortcut to navigate back and forth between your previously visited locations. Try it out, and you’ll quickly understand its usefulness. Additionally, you can use ⌘[ or ] to achieve the same functionality, allowing you to easily navigate through your editing history.

7- ⌃⇧↓ or ↑ (Move Caret to Next or Previous Function or Variables): Sometimes, when you want to sequentially navigate between functions or variables, you can utilize this shortcut. It enables you to move the caret to the next or previous function or variable in your code. While this shortcut can be handy in certain situations, there is also another shortcut (ATOSSA) mentioned at the end of the article that can be even more helpful in various scenarios.

Simply navigate through functions and variables

8- F2 or ⇧F2 (Navigate to the next or previous error/warning): If you encounter compilation errors or lint warnings and you need to navigate through them efficiently, this shortcut will come in handy. By pressing F2 or ⇧F2, you can quickly move to the next or previous error or warning in your code. It’s worth noting that the shortcut prioritizes errors, so after you’ve resolved all the errors, it will shift focus to warnings as well. This allows you to streamline the process of identifying and addressing issues in your code.

The warning is about having an interface with only one function that could be a fun interface or typealias.

9- ⇧⌘E (Toggle Emulator Window): If you’re utilizing the embedded emulator in your IDE, which is highly recommended, you can easily focus, open, and close it using this shortcut. However, please note that this shortcut is not predefined by default. You can add it to your IDE by following the instructions provided in the GIF below. The recording will guide you on how to customize your IDE settings to incorporate the ⇧⌘E shortcut for toggling the emulator window.

Adding custom shortcuts are so simple as you can see

*** ATOSSA Shortcut ***

⌘F12 (File Structure): This shortcut provides a quick and convenient way to examine the structure of a file. By using this shortcut, you can gain a comprehensive overview of a file or class, which can greatly enhance your understanding of its contents. The file structure display includes a list of functions and variables present in the class, as well as any sub-classes that may exist. This feature allows you to swiftly locate specific elements within the file and navigate to them with ease, enabling efficient code exploration and comprehension. Also if you’re using // region .. // endregion approach to organize your code, it will handle them as well.

Surfing and finding things has never been this simple, Using the ordinary find action, is not helpful in some cases.

Useful Plugin

Avoiding using the mouse has some downsides as well, for example, when you see something in your display and you need to move the caret into it, the fastest way is to use the mouse, especially if you are working with Macbook, it is completely reasonable (if you use your thumb). But if you have a physical mouse it’s not that reasonable anymore!

In such a situation you can use the amazing AceJump plugin. It is an easy-to-use and handy plugin that can boost your productivity even more! (How much productivity improvement is enough? There is not enough!).

To use this plugin’s magic, press ⌃; to trigger its search action, Then type the more unique parts of what you see and need to focus on, then use its helper characters shown near the phrase you’re looking for. Take a look at the gif below can clarify what I painfully tried to explain.

Avoiding the use of the mouse can indeed have its downsides, especially when you need to quickly move the caret to a specific location displayed on your screen. While using a mouse, particularly on a MacBook with its touchpad, can be the fastest way to accomplish this, it may not be as convenient if you’re using a physical mouse.

In situations like these, the AceJump plugin comes to the rescue. This remarkable plugin is designed to enhance your productivity even further. With a simple and user-friendly interface, it offers a range of features to streamline your workflow. To harness the magic of AceJump, press ⌃; to trigger its search action. Then, type the most unique parts of what you see and need to focus on. AceJump will display helper characters near the phrase you’re searching for. You can then use these characters to quickly navigate and place your caret precisely where you need it.

The GIF below provides a visual demonstration that should clarify the process I’ve attempted to describe:

We wanted to focus on listOf and change it to mutableListOf in this case.

In nutshell:

1- Install the AceJump plugin

2- Use ⌃; to activate plugin for your search

3- Type some parts of what you’re looking for

4- Choose from plugins suggestions and type it, to focus on what you wanted to

To Be Continued…

You can always replace or add your own favorite shortcuts to replace an easier shortcut or to add more useful actions. For example, Android Studio does not offer a shortcut for showing the gradle window toggling it offline/online, or even synching it! I’ve added ⇧⌘8, ⇧⌘9, ⇧⌘0 for these actions and I’m happier now. We have one of the best IDEs ever and developing can be more fun and performant these days. Try to explore your friend, Android Studio.

Try to add as many practical shortcuts as you need

If you want to have and use my keymap, you can download it from this repository and import it into your own IDE.

P.S.4: Atossa, daughter of Cyrus the Great and wife of Darius the Great, was a powerful and influential empress of the Achaemenid Empire.

Don’t forget about other potential uses of the portal. Image from Pinterest

Mastering Android Studio/IntelliJ (2023) — Part1: Essential Shortcuts You MUST Know

Mastering Android Studio (2023) — Part 2: Teleporting

--

--