Android App Performance Optimization
Improving Android Application Performance
Creating Apps for the Android OS gives a lot of freedom to developers and access to an ever-growing
user base to the application owner. However, the developers face numerous Android application
development challenges in the process. There is numerous android OS version which developers
find hard to keep up when it comes to development.
user base to the application owner. However, the developers face numerous Android application
development challenges in the process. There is numerous android OS version which developers
find hard to keep up when it comes to development.
This turns into a major challenge in Android app development since there are nearly 170+ devices
running the OS. Each device has various highlights with respect to screen size, camera buttons,
keyboard forms, etc. , making it a development nightmare. Remembering a couple of things we
can improve the performance of our application. Following are the factors which degrade our app
performance and the improvements which can be done.
running the OS. Each device has various highlights with respect to screen size, camera buttons,
keyboard forms, etc. , making it a development nightmare. Remembering a couple of things we
can improve the performance of our application. Following are the factors which degrade our app
performance and the improvements which can be done.
Slow Rendering
Slow Rendering is the widest performance problem. Because what the designers need from us and
what we do, may not be the same and trying to do the best visuality, we can sometimes fail in
development.
what we do, may not be the same and trying to do the best visuality, we can sometimes fail in
development.
Rendering is defined in terms of times which ensures that application is running Butterly smooth at
a constant 60 FPS without any dropped or delayed frames.
a constant 60 FPS without any dropped or delayed frames.
What Causes Slow Rendering?
The system tries to attempt redrawn your exercises after each 16ms. This implies that our app has
to do all the logic to update the screen in that 16 ms.
to do all the logic to update the screen in that 16 ms.
what if our app can’t complete the logic in 16 ms?
It’s called a dropped frame. For instance, if your calculation takes 24 ms, this case happens. The
system tried to draw a new picture to the screen, but it wasn’t ready. So it did not refresh anything.
And because of this, the user is looking at the refreshed picture after 32 ms instead of 16ms. If
there is even one dropped frame, the animation will begin not to be seen smooth.
system tried to draw a new picture to the screen, but it wasn’t ready. So it did not refresh anything.
And because of this, the user is looking at the refreshed picture after 32 ms instead of 16ms. If
there is even one dropped frame, the animation will begin not to be seen smooth.
The following tools can be used to improve rendering:
Hierarchy Viewer: Hierarchy viewer is a tool built into an Android device monitor that enables
you to check the features and layout speed for each view in your layout hierarchy. It can enable
you to discover performance caused by the structure of your view hierarchy, helping you then
simplify the hierarchy and reduce overdraw.
you to check the features and layout speed for each view in your layout hierarchy. It can enable
you to discover performance caused by the structure of your view hierarchy, helping you then
simplify the hierarchy and reduce overdraw.
Profile GPU Rendering: Profile GPU rendering gives a quick visual representation of how long
it takes to present the frame of the UI window relative to the 16-ms-per-frame benchmark.
it takes to present the frame of the UI window relative to the 16-ms-per-frame benchmark.
- On your smartphone, go to Settings> Developer Options.
- In the Monitoring section, select Profile GPU Rendering.
- In profile GPU rendering popup, choose the bar as the screen
- Go to the app you want to profile.
Visual Output of GPU Profiler
- The horizontal axis shows elapsed time, and the vertical axis shows time in milliseconds per frame.
- Each vertical bar represents one frame of rendering.
- The green line marks the 16-millisecond target. Every time a frame crosses the green line, the
Application Launching Time
App launch can take place in one of two states, each affecting how long it takes for an application to
become visible to the user.
become visible to the user.
- Cold Start
- Warm Start
Cold Start: A cold begin refers to an application's beginning from scratch, Cold starts to happen in
occur in cases, for example, your application's being launched for the first time since the device was
booted, or because the system killed the app
occur in cases, for example, your application's being launched for the first time since the device was
booted, or because the system killed the app
At the start of a cold start, the system has three tasks. These tasks are:
- Loading and launching the app.
- Displaying a blank initial window for the app immediately after launch.
- Creating the app process.
Warm Start: A warm beginning of your application is a lot easier and lower-overhead than a cold start.
In a warm start, all the systems bring your activity to the foreground.
In a warm start, all the systems bring your activity to the foreground.
If all the activities of your app are still resident in the memory, then the app can avoid repeating the
objects initialization, layout inflation, and rendering.
objects initialization, layout inflation, and rendering.
How to Resolve the app launching Time delay?
- Initialize just those objects that are immediately needed. For example, rather than making global
accesses them.
- Flattening your view hierarchy by reducing redundant or nested layouts
- Move all resource initializations so that the app can execute it lazily on a different thread.
- Allows the app to load and display views, and later update visual properties that depend on
Layouts: The layout is an important part of the Android application that directly affects the user
experience. If your layout is poorly implemented, then your layout may lead to a memory hungry app
with a slow UI. Each widget and layout that you include on your application include initial, layout, and
drawings. For example, using the nested instance of LinearLayout can have a much darker visual
hierarchy.
experience. If your layout is poorly implemented, then your layout may lead to a memory hungry app
with a slow UI. Each widget and layout that you include on your application include initial, layout, and
drawings. For example, using the nested instance of LinearLayout can have a much darker visual
hierarchy.
How to Improve Layout Performance?
Optimizing Layout Hierarchies: The use of basic layout structures leads to the most efficient layout.
However, for each widget and layout you add, initialization, layout, and drawing are required.
For example, using the nested instance of LinearLayout can have a much deeper visual hierarchy.
In addition, using the Layout_weight parameter, using multiple instances of LinearLayout can be
particularly costly because each child should be measured twice. This is especially significant when the
layout is inflated repeatedly, such as when used in a ListView or GridView.
However, for each widget and layout you add, initialization, layout, and drawing are required.
For example, using the nested instance of LinearLayout can have a much deeper visual hierarchy.
In addition, using the Layout_weight parameter, using multiple instances of LinearLayout can be
particularly costly because each child should be measured twice. This is especially significant when the
layout is inflated repeatedly, such as when used in a ListView or GridView.
Re-using Layout with <Layouts>: Reusing layouts is particularly powerful as it permits you to create
reusable complex layouts. For example, a Yes / No Button panel, or Custom Provincial bar with
description text. It also means that any part of your application that is common to many layouts can be
extracted, adjusted separately, then added to each layout.
reusable complex layouts. For example, a Yes / No Button panel, or Custom Provincial bar with
description text. It also means that any part of your application that is common to many layouts can be
extracted, adjusted separately, then added to each layout.
So while you can make individual UI components by writing a custom View, you can do it even more
easily by re-using a layout file.
easily by re-using a layout file.
Loading Views on Demand: Some of the time your layout may require complex views that are rarely
used. Whether they are item descriptions, promotion indicators, or message backs, you can reduce
memory usage and speed up your progress by loading the views only when they are needed.
used. Whether they are item descriptions, promotion indicators, or message backs, you can reduce
memory usage and speed up your progress by loading the views only when they are needed.
Power Usage: Reducing battery usage is an important part of Android's development because this
optimization will ultimately lead to retain the user because sometimes the applications are uninstalled
due to battery drain issues.
optimization will ultimately lead to retain the user because sometimes the applications are uninstalled
due to battery drain issues.
- Tips for improving battery use in Android apps:
- Reduce network calls as much as you can.
- Avoid wake lock as much as Possible.
- Use GPS carefully.
- Use Alarm manager carefully.
- Perform Batch Scheduling
Comments
Post a Comment