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.

Image for post
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.
Image for post
Alt-Cmd-L — Auto realign your code
Image for post
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 :)

Written by

Passionate about learning, and sharing mobile development and others https://twitter.com/elye_project https://www.facebook.com/elye.proj

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store