Tricks and Tips for Android Studio: Part 1

Master some hidden gems of Android Studio

Vinod Baste
Geek Culture
4 min readFeb 7, 2023

--

Photo by Azamat E on Unsplash

You’ll learn how to navigate the codebase, refactor, debug, and use the appropriate tool or plugin at the appropriate time in this article to become a master of Android Studio!

So start your IDE and go through this wealth of productivity suggestions. :]

Getting Started

Since Android Studio is built on IntelliJ IDEA, it gains many keyboard shortcuts from that program. Additionally, several of its panels have handy keyboard shortcuts of their own.

With the help of these simple shortcuts, you can maintain control of everything while keeping your fingers on the keyboard rather than switching between a mouse or trackpad and a keyboard.

You’ll discover some of the most popular keyboard shortcuts in the section after this one.

Code Refactoring

Refactoring may cause unintentional errors in the software and require too much work, according to your first instinct. You’d be correct if your sole choice was to manually refactor your code using a basic text editor. However, it becomes a piece of cake if you delegate all the necessary steps to the IDE and allow it to carry out the refactoring work as an automated process. :]

You’ll learn about various Android Studio tools in this part that reduce the amount of work involved in refactoring to just a few keystrokes so you can do it confidently.

Using Shortcuts to Move Code Around

One of the most frequent actions a developer performs on a daily basis is moving code. You frequently need to move a line of code when making new changes. You may achieve this with fewer errors by using a variety of shortcuts in Android Studio.

Shifting Code Up and Down

You can easily push code up or pull it down by using:

  1. For lines of code:
  • On MacOSX: + + and + +
  • On Windows/Linux: Shift + Alt + and Shift + Alt +

2. For methods:

  • On MacOSX: + + and + +
  • On Windows/Linux: Shift + Ctrl + and Shift + Ctrl +

Moving Sections of Code

Use the F6 key as indicated below to move a portion of code to its own class or to a different package:

Note: This works for all top-level declarations and for Java’s static methods and constants.

Duplicating Code

You can decide to repeat a chunk or a line of code as you are writing it. Use Ctrl + D on Windows/Linux or + D on MacOSX to easily duplicate code:

Deleting Code

You’ve made a mistake, oh no! How quickly can code be removed? The recovery is provided by the keyboard shortcuts + Backspace on MacOSX and Ctrl + Y on Windows/Linux:

Note: These shortcuts work regardless of the cursor’s position on the line.

Renaming Code Constructs

You might need to rename your structures as you write the code. Manual renaming is not an option because it would require too much labor and be subject to human error. Additionally, switching to your mouse takes too long.

To rename anything, use the key combination of + F6. Here’s how it’s done:

  1. Renaming a variable/field:

2. Renaming a method:

3. Renaming a class:

Note: Android Studio takes care of all of the instances of the field, method or class when you execute rename.

Thank you for taking the time to read this article. If you found this post to be useful and interesting, please clap and recommend it.

If I got something wrong, mention it in the comments. I would love to improve

Connect with me on GitHub and LinkedIn.

--

--