Android Studio provides different keymaps (the mapping between shortcut keys and an action). You can see which keymap you are using in Settings->Keymap.
It wouldn’t be practical to list the shortcuts for every keymap so the following will be used:
- Windows: Default
- Linux: Default
- OSX: Mac OSX 10.5+
This is a shortcut to contextually show all the available refactorings for the current selection. This list is keyboard searchable and you can use the number on the left for a quicker access
- Mac: Ctrl+T
- Windows/Linux: Ctrl+Alt+Shift+T
Navigate to parent
If you are in a method that is overriding a parent class (e.g. Activity#onCreate()), this will navigate to the parent implementation.
If you are on the class name, it will navigate to the parent class.
- Mac: Cmd+U
- Windows/Linux: Ctrl+U
Recently Changed Files
This is a variation of the “Recents” popup that lists files that were recently modified locally. It is sorted in order of modification (most recently edited on top). A nice bonus is that you can type to filter the list.
- Mac: Cmd+Shift+E
- Windows/Linux: Ctrl+Shift+E
Jump to Last Tool Window
Sometimes, you return to the editor from a panel but find yourself having to go back to this panel. e.g. browsing find usages. With this, you can go back to a panel without your mouse.
Shortcut: F12 (might interfere with the OS’s default keybindings)
It helps you navigate between your layout and your activity/fragment with ease. There is also a shortcut in the gutter next to the class name and one at the top of the layout file.
- Mac: Ctrl+Cmd+Up
- Windows/Linux: Ctrl+Alt+Home
This is a shortcut to extract a variable without going through the refactoring menu.
This is very useful when you are generating code on the fly as you can avoid typing the variable declaration and go straight to the value. The IDE will then generate the declaration and it will come up with some suggestions on how to name the variable.
- If you want to change the declaration type to something more generic (e.g. List instead of ArrayList), you can press Shift+Tab and it will give you a list of valid types.
- Mac: Cmd+Alt+V
- Windows/Linux: Ctrl+Alt+V
This is a shortcut to extract a parameter without going through the refactoring menu.
This thing is useful when you realize that a method could be generified by extracting one part as a parameter. The way it works is that it will take the current value, make it a parameter and copy the old value as the parameter for each caller.
- You can also keep the original method and have it delegate to the new one by ticking the “delegate” box.
- Mac: Cmd+Alt+P
- Windows/Linux: Ctrl+Alt+P
Following in my streak of extract refactoring, here is the one to extract a code block in a new method.
This thing is extremely useful. Whenever you encounter a method that is starting to become a bit complex, you can use this to safely extract a portion in another method. I say safely because the IDE won’t make a silly copy-paste mistake like we might do.
- Once you are in the extractin dialog, you can change the visibility of the method and the parameter names.
- Mac: Cmd+Alt+M
- Windows/Linux: Ctrl+Alt+M
So you have gone a bit crazy with extraction and now you have too much stuff? You can do the reverse operation, which is called “inline”.
This will work with methods, fields, parameters and variables.
- Mac: Cmd+Alt+N
- Windows/Linux: Ctrl+Alt+M
With this, you can rename a variable, field, method, class and event package. This will, of course, make sure that the renaming makes sense in the context of your app, it won’t simply do a find and replace in all files!
- If you can’t remember this shortcut, you can always invoke the quick fix shortcut and it will always include the rename refactoring.
Pull Up / Push Down
When we talk about pulling something up, we mean that we will take something in the current class (usually a method or a field) and send it to the parent class or interface.
If the parent is a class, the content will be moved. If the parent is an interface, it will declare the method as part of the interface, keep the method in your class and add the @override annotation.
When we talk about pushing members down, that is exactly the opposite operation, we are sending content from the parent class/interface in the child class.
- Mac: Ctrl+T and choose pull members up / push members down
- Windows/Linux: Ctrl+Alt+Shift+T and choose pull members up / push members down