Follow these best practices to optimize your app without sacrificing quality.
Use Baseline Profiles
Baseline Profiles can improve code execution speed by 30% from the first launch, and all user interactions (such as app startup, navigating between screens, or scrolling through content) may be smoother from the first time they run. Increasing the speed and responsiveness of an app leads to more daily active users and a higher average return visit rate.
Use the App Startup library to avoid separate content provider initialization
The App Startup library lets you define component initializers that share a single content provider, instead of defining separate content providers for each component you need to initialize. This can significantly improve app startup time.
Lazily load libraries initialization, or disable auto init of libraries on app startup
Apps consume many libraries, some of which may be mandatory for startup. However, there could be many libraries where initialization can be delayed until after the first frame is drawn. Some libraries have an option to disable auto-initialization on startup or have an on-demand initialization. Use this option to postpone initialization until necessary to help boost performance. For example, you can use on-demand initialization to only invoke WorkManager when the component is required.
Use ViewStubs to lazily inflate layout resources at runtime
A ViewStub
is an invisible, zero-sized View
that you can use to lazily inflate layout resources at runtime. This lets you
delay inflating views that aren't necessary at startup until a later time.
Optimize your splash screen loading on app startup
Splash screens are a major part of app startup, and using a well-designed splash screen can help to improve the overall app startup experience. On Android 12 (API level 31) and higher, there's a new splash screen designed to improve performance. For more information, see Splash screen.
Use scalable image types
We recommend using vector drawables for images. Where it's not possible, use WebP images. WebP is a newer image format supported on Android 4.2.1 (API level 17) and higher. This format provides superior lossless and lossy compression for images on the web. You can convert existing BMP, JPG, PNG or static GIF images to WebP format using Android Studio. For more information, see Create WebP images Using Android Studio.
Additionally, minimize the number and size of images loaded during startup.
Use Performance APIs to understand device capabilities
The performance API for media playback is available on Android 12 (API level 31)and higher. You can leverage this API to understand device capabilities and perform operations accordingly.
Prioritize cold startup traces
A cold start refers to an app starting from scratch, meaning that the system’s process hasn’t yet created the app’s process. Your app typically starts cold if you're launching it for the first time since the device booted, or since the system force-stopped the app. Cold starts are much slower, because the app and system must perform a lot more work, which is not required on other startup types (like warm and hot). System tracing cold startups give you better oversight into the full picture of app performance.