Android Studio 101

Sherry Yuan
Aug 26, 2017 · 4 min read

While interning as an Android developer for 8 months, I picked up a lot of Android Studio shortcuts that made development a lot easier. This is a dump of the most useful ones.

Coding

Reformat code

We all try to write properly formatted code, but end up with too many spaces and bad indenting anyway. Android Studio makes sure we don’t ever have to manually fix our formatting.

Just hit Control + Alt + L on Windows or Command + Option + L on Mac.

Some very badly formatted code
What it looks like after you reformat it using the keyboard shortcut

I do this before every commit so that teammates won’t see my ugly pre-formatted code.

Optimize imports

Similar to reformatting code, you can use Control + Alt + O on Windows or Command + Option + O on Mac to organize your imports and remove any unused ones.

Project quickfix

If you click on a part of your code then hit Alt + Enter on Windows or Option + Enter on Mac.

Android Studio will either directly quickfix your code if it detects any mistakes, or show a menu of suggested common actions.

The project quickfix menu that appears when you click on the allSessions variable

Find a variable or a method declaration

You can hold down Control on Windows or Command on Mac and hover over the variable or method to see information about it, or hold down those keys and click it to go to its declaration.

Show parameters for method

You’re calling a method with 5 parameters, you keep going back to the method declaration to check what you’re supposed to pass in, and Android Studio keeps showing you an angry red squiggle. (That was me for my first few months of Android development)

If you click on the method then hit Control + P on Windows or Command + P on Mac, you’ll see the parameters that the method needs.

Search everywhere

Hitting the Shift key twice lets you search everywhere for classes, methods and variables.

Find in path

If you want to find all occurrences of a String in your project, use Find in path instead.

It’s Control + Shift + F on Windows and Command + Shift + F on Mac.

Figure out where the hell you are in the project

Clicking the target symbol will relocate you, in the Project view, to where your current file is in your project.

Other shortcuts

As you might’ve noticed, most of these shortcuts are just keyboard shortcuts. Android Studio has a lot of them and there are probably some lifesaving ones that I’m not even aware of yet, so go explore on your own!

Running

Monitor your app

So you run your app, tap a button, and the whole thing mysteriously crashes. One of the first things you’ll learn when you start Android development is to check Android Monitor, which can take out that mystery for you.

You open Android Monitor by clicking the tab on the bottom of Android Studio, and it’ll display the crash’s stack trace, as well as any logging statements that you’ve added.

Debugging

Attach the debugger later

You can run your app normally first, then click “Attach debugger to process” when you get to the part of the app that you want to debug. This makes the app start up much faster, and you don’t have to deal with accidentally hitting breakpoints that you don’t care about.

Evaluate expression

When your app is stopped at breakpoint, you can evaluate any expression in that specific state. An “Evaluate Expression…” option will appear in the menu when you right click.

A window will appear, and let you evaluate any expression you want. You’ll be limited to the scope of wherever your breakpoint is, meaning you’ll have access to variables only if they’re in that scope and declared before the breakpoint you’re stopped at.

This is really useful for figuring out what values your variables have at that specific state in your app.

That’s it for now!

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade