Android Studio Tips and Tricks

Master some hidden gems of Android Studio and improve your overall development efficiency with these Android Development tips and tricks. By Nishant Srivastava.

Leave a rating/review
Download materials
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Copying Tooltips

How many times have you been in a situation where Android Studio uses a tooltip to tell you that it’s detected an issue?

You’d like to copy the tooltip’s message and search for it online to find a solution. But to do that, you have to type out the whole message, word by word. Ugh.

Well, actually, Android Studio can copy the text for you. Just move the cursor over the tooltip, press in MacOS or Alt in Windows or Linux and click the tooltip itself.

Keeping Your Code Tidy With Region Blocks

Here’s a neat trick: Oftentimes, you want to group code inside a file into small sections, because there is just too much to look at. Ideally, you should split your code into meaningful classes and functions, but even then you might have a lot to look at inside one file.

To solve this, Android Studio offers what’s known as Region comments, which you can collapse and expand.

To create a region, start a single-line comment and, without adding spaces, write region. Add a space and the name of the region.

Next, at the point where you want to close the region, start another single line comment and, without adding spaces, write endregion. The code looks something like this:

...
//region Print Functions
fun methodOne(){
  // Awesome code
}
fun methodSecond(){
  // Awesome code
}
//endregion

That’s it. You can collapse this using the icon in the caret region on the left-hand side of Android Studio:

Executing Code Blocks

Sometimes, you only want to execute a small block of code instead of running the whole app. The use-case for this is usually when you’re building a utility function and you want to verify that it works properly.

Android Studio provides a very neat solution: Just add a top-level main function. The IDE will let you execute that function locally as if it were a unit test.

Even better, use a live template to set it up by typing psvm and hitting Enter. Super neat!

Check the gif to see how it works:

Sharing Your Project as a ZIP File

Oftentimes, if you’re not using the Git versioning system, you want to share your project as a compressed zip file.

The trouble with doing so manually is that you’d bundle the generated build files along with your project. So you’ll either have to delete all those files or run the gradlew clean command before zipping your project folder.

Android Studio makes this super easy by generating a zip file without including the generated files. You end up with a clean and compressed zip archive, just by using a simple command in the File menu.

Phew, that was a lot of tips and tricks related to Android Studio, but you’ve only touched the tip of the iceberg. Android Studio is full of productivity tricks for developers.

Where to Go From Here?

You can find the final project in the tutorial .zip file, which you can download using the Download Materials button at the top and bottom of the tutorial.

If you’re new to Android Studio, be sure to check out our tutorial, Beginning Android Development with Kotlin, Part One: Installing Android Studio.

You can also learn more Android Studio tips and tricks by reading the official documentation.

I hope you enjoyed exploring Android Studio tips and tricks. If you have any questions or comments, please join the forum discussion below!