Good Practices to Become a Great Android Developer — Part 1

Martin Bacigalupo
Major League
Published in
4 min readAug 17, 2016

--

To become a great Android dev you should take into account a few good practices. Here's a list of the ones we apply and consider are the most important at Lateral View:

1. Use new material design libraries to maintain compatibility with v21 pre-devices.

The past year, on 2015, Google announced the launch of the Android Design Support Library which also contains the latest version of the Android Support Library. It allows us to use a lot of material design components, animations and other stuff on lollipop pre devices. This is very important if you want to keep your app up to date and maintain backward compatibility.

2. Use styles and dimens to build your layouts.

It's really useful to define styles for all your view components. Sometimes it's difficult to be so organized but if you ever worked with css style sheets on web pages you'll understand how good this is. Also, avoid having fixed sizes on your layout files, they should be defined as constants on your dimens.xml.

3. Split a large styles.xml into other files.

This is related to the previous tip. When you have lots of styles defined your styles file becomes really huge and difficult to read. For example, if you want to have even a better architecture it's a good idea that you split this file by categories for example.

4. There should be nothing else in your colors.xml than just a mapping from a color name to an RGBA value. Treat dimens.xml also like colors.xml.

This means that, for instance, red colors should be named "red1", "red2", "red3" and so on. Don't reference their names with a specific view component. Also this applies to dimens file.

5. Every extra functionality on your activities or fragments include it on Managers or Utils as appropriate.

Don't overcharge your activities or fragments with lots of functionalities. In fact activities and fragments should only present data and manage your view events, all the data processing should be on Managers or Utils files.

6. Place your app launcher icons on the mipmap folders, and the rest of the assets on the drawable folders. Also, now it’s possible to use vectors for assets… you should do so!

Now Android has this new folder called mipmap, and here you should place only your launcher icons. This is because they are used at different resolutions from the device’s current density. Also consider using vectors for assets, here's the android documentation for that (remember to use app:srcCompat).

7. Don't forget Tools namespace, there are a few useful attributes here that can make your life easier

For instance, there are very useful attributes for designtime that lets you place dummy data on your inputs so you can see how they look on your layout before running the app. We recommend you to read Designtime Attributes and also Tools Attributes documentation where you can find all this information.

8. Optimize your imports

It’s a good idea that you optimize your imports once in a while or when you finish a project, since this will remove all the unused imports that you have. To do that go to “Code” menu tab on Android Studio and then click on “Reformat code…”. Once the popup is shown select “Optimize imports” option and then click on “Run”.

9. Store release keys on the build.gradle file.

Do not forget to save your release apk file on a safe place and also to take note of your release keys. You can store this information on your project's build.gradle file like this:

signingConfigs {
release {
storeFile file("myapp.keystore")
storePassword "password123"
keyAlias "thekey"
keyPassword "password789"
}
}

10. Prefer Maven dependency resolution instead of importing jar files.

This helps you to easily have the last version of the dependency code, since you can specify if you always want to use the latest version with a '+' extension like this:

compile 'com.android.support:design:23.+'

Also if you don't, Gradle will warn you that there is a recent version of that dependency available with a warning.

11. Be careful with the order you define for your operations inside life cycle methods.

Methods you override that are part of component creation, such as onCreate(), onStart(), onResume(), etc, should chain to the superclass as the first statement to ensure that Android has its chance to do its work before you attempt to do something that relies upon that work having been done. And on methods you override that are part of component destruction, like onPause(), onStop(),onDestroy(), etc, you should do your work first and chain to the superclass as the last thing. That way, in case Android cleans up something that your work depends upon, you will have done your work first.

12. Include unit testing on your application, and use dependency injection to make more configurable tests.

These are two key concepts difficult to incorporate at first but they make a difference on your work. Make your first steps with Dagger 2 library for DI and this Android doc for testing.

Bonus track: stay tuned for last updates on android world at http://android-developers.blogspot.com.ar/

If you want to continue sharpening your skills go ahead and read Good practices to become a great Android developer — Part 2!

Also you can read our articles about Design Principles and Testing to learn more cool stuff about Android!

If you want to know more about technology and innovation, check us out at Lateral View!

--

--