-
Notifications
You must be signed in to change notification settings - Fork 2
Good Practices and Tips
-
Please use new material design libraries to maintain compatibility with v21 pre-devices.
-
Use styles and dimens to build your layouts.
-
Split a large style file into other files.
-
There should be nothing else in your colors.xml than just a mapping from a color name to an RGBA value.
<resources> <!-- grayscale --> <color name="white">#FFFFFF</color> <color name="gray_light">#DBDBDB</color> <color name="gray">#939393</color> <color name="gray_dark">#5F5F5F</color> <color name="black">#323232</color> <!-- basic colors --> <color name="green">#27D34D</color> <color name="blue">#2A91BD</color> <color name="orange">#FF9D2F</color> <color name="red">#FF432F</color> </resources>
-
Treat dimens.xml like colors.xml.
<resources> <!-- font sizes --> <dimen name="font_larger">22sp</dimen> <dimen name="font_large">18sp</dimen> <dimen name="font_normal">15sp</dimen> <dimen name="font_small">12sp</dimen> <!-- typical spacing between two views --> <dimen name="spacing_huge">40dp</dimen> <dimen name="spacing_large">24dp</dimen> <dimen name="spacing_normal">14dp</dimen> <dimen name="spacing_small">10dp</dimen> <dimen name="spacing_tiny">4dp</dimen> <!-- typical sizes of views --> <dimen name="button_height_tall">60dp</dimen> <dimen name="button_height_normal">40dp</dimen> <dimen name="button_height_short">32dp</dimen> </resources>
-
Include unit testing on your application, and use dependency injection to make more configurable tests.
-
Every extra functionality on your activities or fragments include it on the Managers or Utils as appropriate. If there's no Manager or Utils that fits your function, be welcome to create a new class and push it to our skel.
-
Place your app launcher icons on the mipmap folders, and the rest of the assets on the drawable folders.
-
It's a good idea that you optimize your imports once in a while or when you finish a project. 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".
-
Store release keys on the build.gradle file like this:
signingConfigs { release { storeFile file("myapp.keystore") storePassword "password123" keyAlias "thekey" keyPassword "password789" } } -
Prefer Maven dependency resolution instead of importing jar files.
-
Methods you override that are part of component creation (
onCreate(),onStart(),onResume(), etc.), you 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. -
Methods you override that are part of component destruction (
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.