Member preview

2 Habits for Android Code House Keeping

As Android Studio user, this is the very basic thing to do, yet I often forget myself. And often also found some others not knowing it.

The 2 habits (that I still am developing as well ;P) to have a clean code (formatting), is to type the two shortcut as below before you leave each of your code file to another file.

Android Studio — Code Menu.
  1. Alt-Cmd-L : automatic realign your code indentation, remove additional spaces, realign your parenthesis etc. No matter how neat a coder you are, you’ll be surprise what it’ll find.
  2. Ctrl-Alt-O : automatic remove unused imported packages. It’s quite common some of these packages are automatically imported and left there. So some house cleaning would help.
Alt-Cmd-L — Auto realign your code
Ctrl-Alt-O : Automatically remove unused imported packages

Do note this also applies to the XML files.


Have fun forming the habit :). I hope Android Studio will make it default (or there’s a way to auto execute this) whenever I move away from a file. Or at least, make this a single short-cut ;P

Do share if you have better ways of doing this :)