12 Android Studio Tips and Shortcuts to Navigate Your Codebase Faster Header Image

12 Android Studio Tips and Shortcuts to Navigate Your Codebase Faster

We Android developers spend most of our time in Android Studio. In my case, coding mostly means wandering in the codebase from one file to another. I spend more time reading code than writing and you probably are the same.

You need to figure out the context, and find the perfect place to add code that does what you intended. This requires a lot of navigating between files.

Navigating the codebase faster speeds up the overall development. Here are my tips and shortcuts that make navigating the codebase a breeze.

Android Studio Tips and Shortcuts to Navigate Your Codebase Faster

Cmd + Click

If you don’t know already you can Cmd + Click on so many things to get awesome help from Android Studio. Clicking a declaration would list you all the usages or list them if there are more than one. Clicking a variable or a function would beam your caret to its declaration point.

If you want to learn one thing from this article, it should be this.

Jump between parent and child classes

When you are overriding a function in a child class or implementing an interface, you may want to go back and forth. Android Studio has mini buttons available for your convenience. Use them to quickly jump from the overriding function and overridden one.

Navigate dependency injection graph

If you are using Dagger or Hilt, you would want to navigate in the dependency injection graph. Finding where an injected instance is provided or listing all dependency-related files is easy in Android Studio.

Use the graph icons to navigate the dependency graph conveniently.

Find classes or files to navigate

This is one of the shortcuts I use repetitively every day to navigate around. If you want to jump to a class of which you know the name, Cmd + O is your best friend. You can also hit Shift to go to the next tab and search for a file instead.

Use camel case search when finding files

Camel case search is a really powerful text-based search functionality in Android Studio. You can use it in autocomplete or use it when you’re looking for a file to navigate. In the below example we have two very similarly named files: BlueLinePickingViewModel and BlueLinePackingViewModel. You don’t need to type the whole name to jump to this file. You can use just the initials of every word and also the differentiating letter “i” after “P”.

So BLPaVM will return BlueLinePackingViewModel whereas BLPiVM will find BlueLinePickingViewModel in the codebase.

Search some text in the codebase

When I don’t know the file name I’m looking for, I search some text instead.

Hitting Cmd + Shift + F keys to open the Find in Files dialog, I can quickly find the part of the project I want to take a look.

Jump to a line within the file

When you want to visit a specific line in a long file, sometimes it could be easier to move with the Go To Line dialog. Especially, if you are reading source code and not very familiar with that particular file. Hit Cmd + L and write the line number to move your caret there.

Jump to a specific line in any file

You can use the Find a File or File a Class dialogs to jump to a specific line in that file. This could be useful when you are reviewing code in the browser and you want to open that exact location in the IDE. What you need to do is to use # character after writing your query and postfix it with the line number. For example, if you want to go to line 42 of SignInFragment you can write SignInFragment#42 and jump directly to that line.

Also, don’t forget that this becomes more powerful with the use of camel case search.

Navigate caret history back and forth

When I learned about this feature my efficiency in navigating the codebase almost doubled!

Android Studio keeps a history of your caret position within a file and among many files. So if you want to go back (or forward) to see that thing you were looking for seconds ago, you don’t have to remember the file name or the line number.

You can just use Back (Cmd + [) and Forward (Cmd + ]) shortcuts to move your caret in time!

See recent files

This shortcut is not something I’ve known of until recently. If you’re like me and don’t know about this gem yet, here it is: you can hit Cmd + E to list recent files to pick one from.

This would save you some time if you’re working on projects with many many files.

Spot the open file in the project hierarchy

Let’s say you navigated a file using the search or caret history and you would like to jump to the files nearby. This is a common scenario when you want to jump from a Fragment to its ViewModel or to other classes within the same package.

The easiest way to do it is to spot the file in the project hierarchy to get some visuals of the surroundings of the file.

Android Studio has a small button with a sniper scope icon for that.

When I learned about this button, I was really happy.

Also, don’t forget to use Collapse All button at the same row to hide everything to remove the clutter in your project view.

Close all tabs but one

Speaking of removing the clutter, I sometimes hate finding myself trying to reach a tab in the tab bar. That’s when I use an Option + Click to remove all tabs but the open one and breathe a sigh of relief.

I hope these small tips and shortcuts add up and make your life a little bit better when navigating in the codebase in an Android project.