Performance Tips - Smooth Running Android App

Banner Smooth Running Android App Tips

This post is written by Amit Shekhar, and is about making a better Android App (No lags now! only smooth running UI). We will learn what we can do to improve the performance of an Android application.

How to optimize the performance of the Android App?

In order to optimize it, we need to focus on the following:

  • Reduce GC running time
  • Do not do much in the main thread

Steps to be taken to improve the performance:

  • Do not allocate any object if it is not required.
  • Do not allocate object early, allocate object only when it is required. Use lazy initialization.
  • Avoid Auto-Boxing as Integer, Boolean, etc takes more memory as classes like Integer takes more memory so use int where ever possible instead of Integer.
  • Use ArrayMap and SparseArray. Refer to this article, this will show why and when to use ArrayMap and SparseArray to optimize your Android Applications.
  • Use the concept of object pools to avoid memory churn. Learn about the bitmap pool from here.
  • Keep heavy work away from the main thread. Transfer it on the background thread.
  • Use static final for constants (or const val in Kotlin).
  • Avoid Internal Getters/Setters wherever not necessary (direct field access is 3x faster)
  • Don’t leak contexts in inner classes.
  • Use static inner classes over non-static.
  • Use LRU cache for the bitmap to avoid redundant decoding of bitmap, it reduces GC calling again and again.
  • Use StrictMode to find things you did by mistakes like an accidental disk or network access or database query on the application’s main thread in Android Development.
  • Use Profile GPU Rendering: It gives a quick visual representation of how much time it takes to render the frames of a UI window relative to the 16ms benchmark. You can enable it from Settings-> Developer Options-> Monitoring Section -> Select Profile GPU Rendering.
  • And finally, do not allocate a large number of unnecessary objects.

This is how we can improve the performance of an Android Application.

That's it for now.

Happy Learning :)

Show your love by sharing this blog with your fellow developers.

Amit Shekhar

Also, Let’s become friends on Twitter, Linkedin, Github, Quora, and Facebook.