Android Development | Best Practices

Let’s read about some best practices to be followed while designing and developing Android apps.

Jitendra Purohit
Pen | Bold Kiln Press
4 min readMar 6, 2018

--

While building your career as an Android developer, there are a few important things that you should always keep in mind, if you want to increase your chances of success. It doesn’t matter if you want to make your own project or work for a recognized company, there are some essential aspects that should never be neglected while developing an app.

Always maintain the code quality. Quality matters a lot. It’s not only about MVP, MVC, MVVM etc., but also about each piece of code, in each part of your app. Here’s a short description for MVVM, MVC, and MVP.

  • MVC: Three components — View (your UI), Model (data — that view is displaying) & Controller (contains the logic that alters the model depending on the action triggered by UI).
    It’s widely known that MVC is a compound pattern (View and Controller have Strategy Implementation, View itself can be a Composite Implementation and, View and Model are synched through Observer). In this case, Controller doesn’t know anything about View, and the idea is that a View can switch Controllers (for instance, depending upon who has logged to the system) & a single Controller can be used by multiple Views.
  • MVP: Again three components, but with changed dependencies (look at arrows in the diagram). Over here we replace Controller with Presenter (one which presents the changes done in model back to view). The main difference is that Presenter refers back to the view while Controller doesn’t. Normal pattern found here is to create an abstraction of the View (in terms of properties/ events) & Presenter refers to it.
  • MVVM: Model-View-View-Model talks of creating a new model (in addition to your domain model). This model normally adds additional properties from the perspective of View (as we understand that View has controls in addition to data which it’s displaying). For instance, if View had a property IsChecked and Presenter was set in classic MVP, in MVVM Presenter will have that IsChecked Property which View will sync up with. So now a Presenter becomes more like a combination of — View Properties & Model properties which would be synchronized with View. So why not rename Presenter to ViewModel? Do that and you get MVVM.

Always include unit tests. This is the most important part of application development. I recommend running unit tests on JVM, because it’s much faster than running it on an Android device itself or an emulator. If you require any android dependencies, use Robolectric. If you need to mock some objects while testing, use Mockito.

Don’t Use Floating-Point. Floating-point is about 2x slower than integer on Android-powered devices.

Beware of using libraries. Ensure the external libraries you use in application only require needed permissions and do not cause any performance degradation.Think twice before adding any third party library, it’s really a serious commitment.

Get rid of memory leaks with Leak Canary. We’ve all been bitten by memory leaks that cause OutOfMemoryError crashes in our apps at some point, sometimes even in production. Square’s Pierre-Yves Ricau has solved this problem by building LeakCanary, a tool to detect and help fix memory leaks before they ship.

Use Proguard. This will remove all unused code, which will reduce APK size.

Use Android Debug Database. It allows you to view databases and shared preferences directly in your browser.

Perform file and network operations off the UI thread. They take time, and if done on the UI thread can make the app unresponsive, which can lead to “App Not Responding” error. They should always be performed on a worker thread, typically by using an AsyncTask/Loader.

Build apps in record time with Flutter. Flutter is Google’s mobile UI framework for crafting high-quality native interfaces on Android in record time. Flutter works with existing code and is used by developers and organizations around the world. It is free and open source.

Use StringBuffer or Stringbuilder classes when there is a lot of modifications to string of characters.

And keep testing on different OS versions and devices.

Happy Learning 🙂

If you are looking for an expert help in app development and promotion, you’ve come to the right place. Feel free to contact us and send your questions! We are ready to start working with you today.
P.S. We have helped early stage startups and other big names including Uber, Bank of Baroda and a whole lot of others, building mobile, web applications.

--

--