Skip to main content


 

Optimising Android Launch: Mastering App Startup & The Modern Splash Screen

The first few seconds of an app’s life determine a user's first impression. A slow start or a flickering white screen can lead to immediate uninstalls. In this guide, we’ll look at how to streamline your initialisation using the App Startup Library and ensure a seamless visual transition with the Android 12 Splash Screen API (with full backward compatibility for API 29).


Part 1: The App Startup Library

Traditionally, apps initialised multiple components using separate content providers. This adds overhead and slows down launch time. The Jetpack App Startup library allows all components to share a single content provider, significantly improving performance.

Why use it?

  • Performance: Shared content provider reduces overhead.

  • Order: Explicitly set the initialisation sequence.

  • Simplicity: Both library creators and app developers use a unified interface.


Part 2: The Modern Splash Screen API

Starting in Android 12, the OS introduced a native splash screen. For older systems (like API 29/Android 10), we use the core-splashscreen library to bridge the gap.

If your app shows a "white flicker" on older devices, it’s usually because the postSplashScreenTheme hasn't been set correctly or initialisation is happening on the main thread.

Step 1: Configure Your Themes

Update your res/values/themes.xml to include two distinct themes: the "Starting" theme and the "Main" theme.

XML
<resources>
    <style name="Theme.App.Starting" parent="Theme.SplashScreen">
        <item name="windowSplashScreenBackground">@color/background_color</item> 
        <item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher</item>
        <item name="postSplashScreenTheme">@style/Theme.Book</item> 
    </style>

    <style name="Theme.Book" parent="Theme.Material3.DayNight.NoActionBar">
        <item name="android:windowBackground">@color/background_color</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>
</resources>

Step 2: Manifest Setup

Point your Application and Launcher Activity to the Starting theme.

XML
<application
    android:name=".BookApplication"
    android:theme="@style/Theme.App.Starting">
    
    <activity
        android:name=".MainActivity"
        android:exported="true"
        android:theme="@style/Theme.App.Starting">
        </activity>
</application>

Part 3: Implementing in MainActivity

To prevent the screen from disappearing before your data (like Billing or User Preferences) is ready, use setKeepOnScreenCondition.

Kotlin
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        // 1. Install splash screen before super.onCreate
        val splashScreen = installSplashScreen()
        super.onCreate(savedInstanceState)

        var isReady = false

        // 2. Load critical data (DataStore, Billing Manager, etc.)
        lifecycleScope.launch {
            // Wait for your initialization logic here
            isReady = true 
        }

        // 3. Keep the splash screen visible until data is loaded
        splashScreen.setKeepOnScreenCondition { !isReady }

        setContent {
            if (isReady) {
                BookTheme {
                    MainAppScreen()
                }
            }
        }
    }
}

Common Troubleshooting: The API 29 White Screen

On Android 10 (API 29), the system doesn't have a native splash screen. The core-splashscreen library draws a "fake" view. If you experience flickering:

  1. Check for Startup Conflicts: Ensure libraries like Google Mobile Ads are initialized on a background thread (Dispatchers.IO) inside your App Startup initializers.

  2. Match Backgrounds: Ensure your android:windowBackground in your main theme exactly matches the color you use in your Compose/XML layout.

  3. Synchronous Tasks: Avoid accessing large databases on the Main Thread during onCreate.


Official Resources

Happy Coding!

Comments

Popular posts from this blog

Firebase with android: An Overview of Products and Usage

Introduction: In the evolving landscape of mobile application development, understanding user behaviour, managing user identity, and delivering personalised communication are critical components of a successful digital product. Google provides a suite of powerful tools through Firebase and Google Analytics that help developers build, improve, and grow their applications efficiently. This article explores Google Analytics , Firebase Authentication , Firebase Cloud Messaging (push notifications), and other core Firebase products , along with their practical uses. Google Analytics Google Analytics for Firebase is a free app measurement solution that provides insights on app usage and user engagement. Unlike traditional Google Analytics, this version is tightly integrated with Firebase services, making it highly useful for mobile and cross-platform apps. Key Features: Event tracking : Automatically or manually track user actions like screen views, button taps, purchases, etc. User segm...

Android Studio Release Updates

JetBrains's  Android Studio’s 10 year anniversary      I remember the major change which has taken place since I started learning android is Android Studio migration from Eclipse. Android Studio’s 10 year anniversary. Watch official youtube : Android Studio’s 10th birthday: our favorite moments!      In December 2014 , Google launched Android Studio, Google's official Integrated Development Environment (IDE) based on IntelliJ and it discontinued the Android Developer Tools (ADT) plugin for Eclipse, which means it’s time to leave eclipse behind.        Fortunately, we had simple solution to migrate, Android Studio offered a better experience for Android developers and its migration functionality does most of the work for you.      Open Android Studio and click on the option:  Import project (Eclipse ADT, Gradle, etc) Before Android studio      1. users had to go download a JDK, then download Eclipse...

Google re-branded the support Android libraries to AndroidX

It is important to note, you cannot mix AppCompat and Jetpack in the same project. You must convert everything to use Jetpack if you want to upgrade. The support library artifacts are being deprecated and all future development is going into AndroidX , so there's no avoiding this migration. Alan Viverette sums this up nicely: “There won’t be a 29.0.0, so Android Q APIs will only be in AndroidX” The stable release of 28.0.0 will be the final feature release packaged as android.support . All subsequent feature releases will only be made available as androidx-packaged artifacts. Below tips will give you a clearer transition path. The current version of AppCompat (v28.x) is exactly the same as AndroidX (v1.x). In fact, the AppCompat libraries are machine generated by changing maven coordinates and package names of the AndroidX codebase. For example, android.support.v7.app.AppCompatActivity is now androidx.appcompat.app.AppCompatActivity For a complete listi...