We typically spend most of our workday in our IDEs. And as modern IDEs have become very powerful, we have often failed to utilize them to their full potential. This post from the mobile development series provides a brief description of tips and tricks on how to make Android Studio work for you, so that you spend less time by typing and navigating and more time by actually building things.
Shortcuts
Complete Statement
Ctrl + Shift + Enter
IntelliJ automatically adds missing braces, or just moves a cursor to the next line.
Start New Line
Shift + Enter
This is useful when dealing with chained calls.
Multiple Cursors
Double Ctrl + arrow keys
For bulk editing similar codes.
The last pop-up on the GIF is aptly named the String Manipulation plugin.
Alternatively, to create a separate caret you can also use:
- Alt + J to add a caret on the next occurrence of this word/name
- Ctrl + Alt + Shift + J to select all occurrences
- press and hold Shift + Alt and click at the next location of the caret
- Alt + Shift + G to add carets to the ends of the selected lines
To delete all added carets, press Escape.
Column Selection Mode
Alt + Shift + Insert
By default, IntelliJ uses a line selection mode. You can press Alt + Shift + Insert at once to enable the column selection mode. Press Alt + Shift + Insert again to return to the line selection mode.
Remove Line
Ctrl + Y
Delete one or multiple lines.
Learn more about technology stack for Android application.
Product Discovery Lab
Free product discovery workshop to clarify your software idea, define requirements, and outline the scope of work. Request for free now.
IntelliJ Features
Changelists
Changelist is basically a way to divide your Git staging area into several groups. By default, IntelliJ has only one “Default Changelist”, but you can also create your own.
You can also “shelve” changelists, similarly to git stash, but from our point of view the IntelliJ variant to be much more powerful.
You may also use Shelf to store code for manual testing. For example, a piece of code to temporarily make you a premium user. Or use hard coded fake server responses, so that you can test how your app behaves to certain responses.
You can take a look at IntelliJ reference here and here for further information on how to create, manage, and shelve changelists.
Clipboard History
Ctrl + Shift + V
IntelliJ keeps track of everything that you copy.
Local History
According to IntelliJ reference:
Local History helps you constantly tracks every change made to a project independently of version control.
Unlike version control systems, which only keeps track of the differences made between commits, Local History offers much more. It automatically records your project’s current state as you edit code, run tests, deploy applications, and so on, while maintaining revisions for every meaningful change made externally and from the IDE.
It also acts as your personal version control system. Local History also lets you restore deleted files, bring back separate changes, or roll back to any state of a file even if no version control is enabled for your project. This happens even if an unwanted change was made after your last commit. It may also serve as a recovery source if your computer restarts unexpectedly before you have the opportunity to take action.
To view this history:
- select the file or directory of interest (if you deleted a file, select its parent directory)
- right-click and choose Local History > Show History from the context menu
- there you can view and revert
- past changes
Creating Files
Why do File > New > File > Kotlin class/file every time you create a file? Just assign it a shortcut!
Go to Settings > Keymap > Main Menu > File > New and assign a shortcut to the types of files you create frequently. For example, we use:
- Alt + S for Kotlin files
- Alt + D for packages/directories
- Alt + W for Android resource files
- Alt + F for text files (i.e. Markdown, JSON)
CamelHumps
CamelHumps is a feature that identifies parts of compound names composed according to CamelCase, wherein each part starts with a capital letter, or when parts of a compound name are separated by underscores. For example, a compound name “MyVideoPlayerUtils” contains “my”, “video”, “player”, and “utils” parts.
By default, IntelliJ won’t honor CamelHumps. You can force it to honor, by simply going to Settings > Editor > General > Smart Keys and tick Use "CamelHumps" words. Using this method IntelliJ will always use CamelHumps. Or you may assign the shortcuts to use CamelHumps sometimes and as needed(search for “in Different “CamelHumps” Mode”).
Auto Imports
Do you hate manually adding imports? Well, IntelliJ can do the work for you.
- Open Settings > Editor > General > Auto Import
- Tick Add unambiguous imports on the fly and Optimize imports on the fly.
Replace in Path
Replace every occurrence in the entire project/module/directory.
This is useful when a dependency has migrated to a different package.
Jira Integration
If you include Jira task numbers into commit messages, you can istruct Android Studio to highlight those numbers and also make them clickable.
To enable this go to:
- Settings > Version Control > Issue Navigation
- click Add JIRA pattern
- paste the Jira installation URL
You can also manage Jira tasks right from the IDE. IntelliJ can also:
- list tasks
- move tasks to different states
- create a separate branch for current task
You can read more here on how to connect IntelliJ with your issue tracker.
Android Device
Scoop
According to @paphonb, the developer behind Scoop:
… [Scoop] saves the stack trace of a crashing app and displays all crashes in a list so you don't have to look through a long logcat anymore. Additionally you get a notification on every crash (configurable) which already displays the most important information.
As seen in the screenshot above, this app not only works with debuggable apps, but also with ANY other app, including system apps. So you can provide a crash stack trace for app developers to make their lives a lot easier. Or you can simply install this app on your QA’s devices and make your life easier.
Originally Scoop was an Xposed module, but you can use it without root.
To set up for non-rooted users:
- Download and install the latest version from here.
- Run `adb shell pm grant xyz.paphonb.scoop android.permission.READ_LOGS`
- Open the app.
- You should see a notification indicating that the app is running.
For rooted users:
- Download and install the latest version from here.
- Just launch the app and grant it root permission.
If for some reason, Scoop won’t automatically start after restart on my device. It can be manually started. Or you can use Tasker to automate this.
Developer quick tiles
Quick tiles are what is shown when the notification shade is pulled down.
This comes in handy as a quick way to slow down animations or profile rendering.
To enable this feature:
- Open settings
- Search for “Quick settings developer tiles” under “Developer options” (your vendor might name it differently)
- Enable the tiles you would like to see under the notification shade
By default, the tiles are added at the beginning, but can be easily rearranged.
Plugins
Key Promoter X shows a notification every time a button is pressed that has a keyboard shortcut associated with it.
ADB Idea adds useful ADB commands to Android Studio:
- Uninstall App
- Kill App
- Start App
- Restart App
- Clear App Data
- Clear App Data and Restart
- Grant/Revoke Permissions
- Start App With Debugger
- Restart App With Debugger
JSON To Kotlin Class: Paste a piece of JSON, and it will automatically generate its Kotlin data class representation.
Additional resources
- Android Studio: Tips and tricks talk at Google I/O’19
- Android Studio: Debugging tips n’ tricks talk at Google Dev Summit ’19
Axon is ready to provide you with senior tech talent and product development expertise to build world-class software. Let's talk about how we can help you.