5 Simple steps to optimize your next Android Application in 2022

5 Simple steps to optimize your next Android Application in 2022

Ever thought of decreasing your app (APK) build size or improving its performance? If yes, then let's learn the essentials for making your app the best!

What is App performance? πŸ€”

Application performance defines all about the overall experience and total size of the application after you build a release. It's very common stuff that people will use those applications which are smaller in size and has better performances on low-end devices.

So, it becomes very important for a developer to supply a compact-sized high (smooth) performing application to the client(users).

But this issue gets neglected by the new developers or some experienced developers too as this topic is very much underrated.

5 Major Points

Use R8 for your release APK πŸ”

It's famous for making the app size smaller. But how did this happen? This R8 works with Android Proguard and deletes all the unnecessary functions, classes, resources, shortens the variable/object names, etc. This also saves your code from getting reverse engineered as the latter gets confused by the variable names that R8 internally converts into.

Turning ON R8 support for your project

image.png

Read More

Use android Profiler

This tool, which is inbuilt on your android studio comes with the awesome feature of giving networking, fast or slow, memory and battery statistics while using this app. It's similar to Chrome Devtools. It allows the developers to analyze the whole application and find where the app uses more amount of resources than needed.

It looks like this(Just run your application on the emulator or select any file from your system):

image.png

Read More

Caching

When we make a network request and fetch the remotely stored data on our application, it takes a certain amount of resources to perform the same. So if the data is fetched, again and again, it makes a large bandwidth consumption and resource waste as we are fetching the same data again and again. But if we store the data as cache just after the first call, the resource consumption will drastically decrease and will ultimately result in a better application with a great user experience.

Use a good library to cache the image URL like Glide.

You can find many resources on Database caching for the Rest API, etc on google.

Use Fragments as much as possible instead of making Activities

Fragments, in comparison to Activities, can run with low RAM consumption and are lighter. It helps the application to perform better on every device making it more engaging for the user.

StringBuilder in place of String

As we know, Strings are immutable, so if we concatenate another string to it, it makes many inefficient trash operations. But in the case of StringBuilder, this same concatenation will take very very less time to process. So take this a tip, and if you want its practical demonstration use the Android Studio's CPU visualizer and see the execution time and compare them.

Bonus Point 🀩

Use the Threading Efficiently

Primarily, there are two types of threads:

  1. UI Thread
  2. Background Thread

If we run any calculation, network requests, querying data from local databases, loading images from remote URLs, or parsing a JSON, on the main(UI) thread, blocks the main thread from further processes. So it is always advisable to make the above-mentioned processes inside a background thread.

In the Modern Android Development scenario, this thing can easily be done with Coroutines. It is very simple to use Jetpack Component.

Read More about Coroutines

Hope you learned something new hereπŸš€. Try to Build your next project keeping these points in your mind and you will see a drastic change on the size and performance.

Thanks for making a read. Have a nice day :)

Did you find this article valuable?

Support LearnDroid by becoming a sponsor. Any amount is appreciated!

Β