Join CTO Moataz Soliman as he explores the potential impact poor performance can have on your bottom line. 👉 Register Today

ebook icon

App Performance

General

Key Performance Optimization Strategies for Your Android App: Part 1

Key Performance Optimization Metrics for Your Android App

As mobile apps continue to play an increasingly integral role in our daily lives, user expectations have kept pace. Today, it’s not enough for your app to provide a useful feature; your users also expect it to do so quickly and without errors, while consuming minimal battery life.

To develop a high-quality Android app, it’s imperative to keep your app’s stability and performance in mind throughout the app development cycle. In this series of posts, we’ll take a look at the key metrics to consider to improve your app’s performance on Android devices.

Optimizing Your Mobile App’s Performance

App launch time

Your app’s launch is your first chance to make a positive first impression on your users, and, according to research, more than 60% of mobile app users expect apps to launch in four seconds or less.

Moreover, from a technical perspective, app launch time tends to be a strong indicator of an app’s overall quality. This is why you need to monitor your app’s launch time, understand exactly what happens during the process, and continuously try to reduce the time it takes for your app to become interactive.

You can learn more about app launches and how to monitor and optimize them in the following posts:

App size

The size of an APK affects how quickly your app loads, its launch time, and the amount of memory and power it consumes. Let’s take a look at some best practices that will help keep your APK size to a minimum.

Resources and assets

Resources and assets like images, videos, and raw data usually comprise a large portion of the total APK size. In general, it’s best to remove any unused files or resources and exclude them from your final APK or AAB (Android App Bundle). Also, you should always consider the resolution and size of images you use for icons and other UI elements to ensure you don’t add any unnecessary megabytes.

Finally, the libraries that your app depends on may include a lot of resources that your app doesn’t use or need. Make sure you configure Android’s Gradle to shrink or remove any unused resources when you build your APK by enabling the shrinkResources option in your module build file.

Image and icon formats

For the images you include in your app, always try to use a drawable vector format like SVG over other formats like PNG. By using the SVG format, you can avoid having to add multiple copies of the same image to support different screen resolutions and densities. SVG images can be scaled without sacrificing quality, and they render efficiently in most cases.

In cases where you need to use PNG, avoid using a higher resolution than absolutely necessary. High-resolution images will increase the size of your APK, decrease UI responsiveness, and consume more memory and power to render.

The WebP format is a popular alternative to formats like PNG as it provides lossy compression (like JPEG) and transparency (like PNG) but provides superior compression to either.

Lastly, consider using tools like ImageOptim to optimize your images to further reduce their size.

Note: Some SVG images can have paths that are complex to render and, as a result, consume more resources than PNGs. When choosing an SVG image for your app, always keep in mind the memory and power it will need to render.

Use AAB instead of APK

Android App Bundle (AAB) is Android’s new format to export and distribute Android apps. When you package your app as an AAB, Google generates distinct APKs for different devices, only including the files needed for a specific device architecture, target screen resolution, and more, resulting in a smaller APK file for your users to download.

Network performance

According to research, 55% of users cite long load times and poor responsiveness as the top frustrations they face with mobile apps. Network calls are common contributors to long load times, and the vast majority of apps use the network to make API calls that deliver their features.

Monitoring and optimizing your app’s network performance is critical if you want to ensure short loading times and provide a better user experience. Read on for some best practices for improving your app’s network performance.

Avoid loading high volumes of data in splash screens

Blocking your users on a splash screen while your app downloads large amounts of data provides a poor user experience and negatively affects your app’s startup and load times. Always try to first load the minimum amount of data that gets your app responsive to user input, then load the rest of the data in small chunks in the background.

Sync data in the background

Whenever your app needs to sync data with the backend during an active session, try to do this in the background. You can notify your users once the sync is complete if further user action is required.

Cache frequently-needed data

Another tactic you can use to avoid blocking your users with a loading bar is caching frequently-used data and data from the previous session. This will allow you to display the cached data to your users while your app updates the data in the background.

The data your app will display might not be as up-to-date as it could be, but this approach provides a better experience than forcing your users to wait while your app loads all the data over an unreliable network.

Provide visual feedback

Sometimes you have no choice but to block your users while your app completes a network request. In these cases, always try to display a loading bar so your users don’t think the app froze. The loading bar will also allow users to follow the request’s progress.

Of course, loading bars are not the only solution. You can use bars, wheels, shimmer effects, or any other visual representation of the request’s progress.

Monitor and optimize your network requests

To improve your app’s network requests, you need to first gain visibility over their performance and understand what causes them to lag or fail. App Performance Monitoring tools like Instabug can help you keep an eye on how your app’s network requests are doing.

Instabug allows you to easily track your network throughput, check client-side and server-side failure rates, and identify slow requests, as well as dig into specific requests and see their request and response payload sizes.

Memory use

Memory use is a critical part of your app’s performance. You should take steps to avoid common pitfalls that eat memory and focus on making your app use memory efficiently.

Avoid memory leaks

Memory leaks are a common issue in app development that occurs when unused objects are held in memory and the garbage collector is not able to recognize them. This causes these objects to remain in memory unused, reducing the amount of memory available for the app.

Avoid passing or referencing an object with a short lifecycle in a class or object with a longer one. For example, keep the reference for the view context—which tends to have a short lifecycle—in the presenter or data layer. In fact, you should use app context instead of view context whenever possible.

For more details about Android memory leaks and how to avoid them, check out our post: How to Fix Memory Leaks in Your Android App.

Avoid Out Of Memory (OOM) errors

Out Of Memory (OOM) errors occur when the Java Virtual Machine cannot allocate an object in the heap because it has run out of memory. This usually indicates that you’re either holding onto objects for too long or trying to process too much data at once.

In Android, OOM errors can occur when you leak too many objects, process large images, or manipulate long string objects such as a large network response. While Android’s fragmentation does not make it easy, you should generally know your limits for memory usage and keep them in mind while developing your app. In addition, refrain from performing intensive operations or too many concurrent operations to avoid OOMs errors.

Up Next

In Part Two, we’ll take a look at monitoring UI hangs, detecting dropped frames, and inspecting UI rendering.

Learn more:

Instabug empowers mobile teams to maintain industry-leading apps with mobile-focused, user-centric stability and performance monitoring.

Visit our sandbox or book a demo to see how Instabug can help your app

Seeing is Believing, Start Your 14-Day Free Trial

In less than a minute, integrate the Instabug SDK for iOS, Android, React Native, Xamarin, Cordova, Flutter, and Unity mobile apps