Just moving on from eclipse to android studio – now it’s the official IDE for android and want to give a try.
Some problem I was facing is that I’m too attached with eclipse (sublime text too) so I hate the moment when I need to google some shortcut to make my coding session as efficient as possible.
But overall I love two things that android studio offer :
1. use gradle as default for managing plugin and library
2. the preview layout that lighter than in eclipse
So I decide to move on from eclipse and here some shortcut I’d love to share with you so your zen mode will not disturbed by googling mode for finding shortcut
Imagine that you must go to a class named “MainActivity”, just use this shortcut and start typing “MainA”.
Works like the “Open Class” shortcut but on every files in your project. It is very useful to open your AndroidManifest.xml or anything that sits in the res/ or assets/ folder.
A very powerful but little less known variation of the previous tips: You can use this to go directly to a method or field by searching its name!
For example, if you know that you have a method named getFormattedDate() somewhere in your project, you can type it in the Open Symbol dialog to go directly to it.
You can enter incomplete strings and it will work. For example. if you are searching for a class named “ItemDetailFragment”, you can actually type “IDF” and it will find it.
Imagine that your colleague just told you that the juicy part is in ExcitingClass at line 23. You can open the file directly by appending a “:” to the class name in the Open Class dialog. e.g.:
You can also combine it with partial matching and type something like:
Recently opened files
This will show a popup listing the files you navigated to previously.
Recently edited files
Same as the above but listing only files that have been edited.
Start typing to filter the list.
To understand this shortcut, think about how the back and forward buttons work in a web browser. Now, instead of thinking in web pages, think about source code! So when you drill down in code or open a new file, the IDE will remember where you where before, allowing you to quickly go back.
Last Edit Location
This is a variation on the “Navigate Back” shortcut that cycles between the locations where you typed something.
Picture yourself fixing a nasty bug. You think you have the solution so you start fixing it but then realize that you have to look at the android source code and a couple other classes in your project. You enter a function, which leads you to another class, which leads you to another thing and 20 steps later, you finally have the insight needed to complete your fix… but in which file and at what line where you again? Just use this shortcut and you are right back at the exact line where you stopped writing.
In a Persistent Panel
Shows where something is used. For a class member, it will show where reads and writes are made. For a method, it will show where it is called. For a class, it will show where new instances are created.
You can use the arrow keys and the return key to navigate trough results. You can then press the escape key to go back to the editor.
Same as before but shows the information in a popup.
Goto Declaration/Implementation (Drill Down)
Here are three shortcuts to drill down into a symbol:
Goes to the declaration of the class, method or variable. Mostly useful on classes and methods since it redirects to the implementation.
Shows a list of all the classes/interfaces implementing the selected class/interface. Also works on methods to find where they are implemented/overriden. On variables, it has the same effect as Goto Declaration
Goto Type Declaration
When the caret is on a variable, it will go to the declaration of its type. For example, if I have the following line:
Developer whe = new Developer("whe");
If the caret is on the variable “whe”, this shortcut will go to the declaration of the “Developer” class.
This will open the parent of the current symbol. Pretty much the opposite of Goto Implementation. If the cursor is in an overriden method, it will open its parent implementation. If the caret is in a class but outside the method or on the class name, it will open the parent class.