Android App Optimization
Increase user engagement by Improving your application’s performance.
It's challenging for developers to follow all the guidelines and best practices while Development to improve the performance.
Keeping a few things in mind to improve the performance of your application. This article will focus on some of the issues which are easily noticed by the end user and can affect your app’s performance.
1. Application launch time.
2. Slow Rendering.
Let’s talk one by one
Application launch time:
For a better user experience application should be fast and responsive, Slower startup time affects the user experience and the result could be poor rating or less active user. App Start time is the time taken for a user to see the home page content.
Let's Understand app-start internals
App launch can take place in one of three states, each affecting how long it takes for your app to become visible and responsive to the user: a) cold start, b) warm start, c) hot start.
Cold start is the time taken by an application to start from scratch while in other states the system needs to bring the running app from the background to the foreground.
a) Cold start?
Cold starts happen in cases such as your app’s being launched for the first time since the device booted, or since the system killed the app.
At the beginning of a cold start, the system has three tasks. These tasks are:
- Loading and launching the app.
- Displaying a blank starting window for the app immediately after launch.
- Creating the app process.
Once the system creates the app process, the app process is responsible for the next stages which are - Creating the app object.
- Launching the main thread.
- Creating the main activity.
- Inflating views.
- Laying out the screen.
- Performing the initial draw.
Once the app process has completed the first draw, the system process swaps out the currently displayed background window, replacing it with the main activity. At this point, the user can start using the app.
The cold start of the app can be delayed due to the following mistakes.
Is there any heavy operation in on create of the activity?
Are there any reflection/serialization calls being performed on the UI thread?
Get Dhananjay Yadav || Android Developer’s stories in your inbox
Join Medium for free to get updates from this writer.
Can we avoid creating unnecessary objects Or make them lazy as much possible?
Can the view hierarchy be flattened to have faster rendering?
How to improve the cold start time?
Following are some ways to improve the cold start time.
Try to make Flat UI as much as possible, use theme instead of the layout if possible (In case of Splash theme it will avoid the unwanted cost of setContentView()).
Move the 3rd party libraries and unnecessary SDK out of application’s onCreate or initialize them on a background thread.
Avoid direct API calling instead try to execute them in the background or asynchronously( Use of RX Java will be better).
Use lazy initialization (Use dagger2 dependencies injection for lazy initialization or Kotlin’s lateinit , lazy if required).
Convert the PNG images to WebP for smaller memory footprint.
Avoid file access & JSON deserialisation during app startup.
Avoid creating global static objects, instead, move to a singleton pattern, where the app initializes objects only the first time it accesses them.
b) Hot start?
Hot start, all the system does is bring your activity to the foreground. If all of your application’s activities are still resident in memory, then the app can avoid having to repeat object initialization, layout inflation, and rendering.
c) Warm Start?
If The user backs out of your app, but then re-launches it. The process may have continued to run, but the app must recreate the activity from scratch via a call to onCreate().
Hot and warm start can be improved by Micro Optimisation.
Micro Optimisation:
Don’t do work that you don’t need to do.
Don’t allocate memory if you can avoid it.
Avoid creating unnecessary objects.
Prefer static over virtual.
Use static final for constants.
Conclusion: By following this step we can reduce the application start time by at least 50–60%.
Tools to identify performance bottlenecks:
In the next part, I will discuss the Slow Rendering and how to overcome.
If you like this article, please don't forget to click on 👏.






