Android splash screen with the SplashScreen API

Add a splash screen with the Android 12 SplashScreen API and the core-splashscreen library, keep it up while data loads, size the icon correctly and migrate from a SplashActivity.

Written for Android 12 (API 31) and newer, androidx.core:core-splashscreen 1.0.1 for older versions, Kotlin

In this JavaAnt guide, we implement an Android splash screen. Since Android 12, every app gets a splash screen whether you build one or not: the system shows your launcher icon on a plain background while the app process starts. The work left to you is making that screen look like your app, keeping it up while you load what the first screen needs, and removing any old splash activity that now shows a second splash after the system one. This tutorial does all three with the SplashScreen API and its AndroidX compatibility library, which brings the same behaviour back to Android 6.

How the system splash screen works

When a user taps your icon and the process is not running (a cold start), Android draws a window from your launcher activity's theme immediately, before any of your code runs. On Android 12 and newer, that window shows the icon centred on a background colour, then animates away when your first frame is drawn. You control what appears through theme attributes, and you control how long it stays through one callback. Warm starts, where the app is in memory, may show it briefly too.

Add the compatibility library

The platform API exists only on API 31 and newer. The AndroidX library gives one code path for every version from API 23:

app/build.gradle.kts
dependencies {
    implementation("androidx.core:core-splashscreen:1.0.1")
}

With it, older versions show a static version of the same screen; animated icons and the icon background colour only take effect on Android 12 and newer.

Define the splash theme

Create a theme that inherits from Theme.SplashScreen and names the theme your app uses after the splash:

res/values/themes.xml
<resources>
    <style name="Theme.App" parent="Theme.Material3.DayNight.NoActionBar">
        <!-- your normal app theme -->
    </style>

    <style name="Theme.App.Starting" parent="Theme.SplashScreen">
        <item name="windowSplashScreenBackground">@color/splash_background</item>
        <item name="windowSplashScreenAnimatedIcon">@drawable/ic_splash</item>
        <item name="postSplashScreenTheme">@style/Theme.App</item>
    </style>
</resources>

windowSplashScreenAnimatedIcon takes a drawable, a vector, or an animated vector drawable. postSplashScreenTheme is required: it is the theme the activity switches to once the splash ends. Forgetting it is the usual cause of an activity that suddenly has the wrong colours or crashes with "You need to use a Theme.AppCompat theme".

Then apply the starting theme to the launcher activity, or to the whole application, in the manifest:

AndroidManifest.xml
<activity
    android:name=".MainActivity"
    android:exported="true"
    android:theme="@style/Theme.App.Starting">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Install it in the activity

Call installSplashScreen() before super.onCreate(). It reads the theme, sets up the splash and switches to postSplashScreenTheme:

MainActivity.kt
class MainActivity : AppCompatActivity() {
    private val viewModel: MainViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        val splashScreen = installSplashScreen()
        super.onCreate(savedInstanceState)

        splashScreen.setKeepOnScreenCondition { viewModel.isLoading.value }
        setContentView(R.layout.activity_main)
    }
}

The same call works in a ComponentActivity that uses setContent { } for Jetpack Compose.

Keep the splash while data loads

setKeepOnScreenCondition is checked before each frame is drawn. While it returns true, the splash stays. Back it with real state, such as whether the signed-in user or the first page of data has loaded:

MainViewModel.kt
class MainViewModel(private val repository: SessionRepository) : ViewModel() {
    private val _isLoading = MutableStateFlow(true)
    val isLoading: StateFlow<Boolean> = _isLoading

    init {
        viewModelScope.launch {
            repository.restoreSession()
            _isLoading.value = false
        }
    }
}

Keep this short. The splash exists to cover process start, not to hide slow network calls; if loading can take several seconds, end the splash and show a loading state in your UI instead. A splash that never ends because a request hung is a real failure mode, so give the load a timeout.

Size the icon

The system crops the icon to a circle and scales it, so artwork outside the safe area gets cut off. The dimensions from the Android documentation:

IconCanvasVisible circle
Without an icon background288 × 288 dp192 dp diameter
With an icon background240 × 240 dp160 dp diameter

Use windowSplashScreenIconBackgroundColor when your icon needs a contrasting plate behind it. If you set nothing, Android 12 and newer use your launcher icon, which is often fine for a first version.

An animated vector drawable gives an animated splash on Android 12 and newer. Google recommends keeping the animation to 1,000 ms or less, and you set its length with windowSplashScreenAnimationDuration. The splash is visible while the app starts, so a long animation just delays the user.

Customise the exit animation

By default the splash fades out. To slide it away instead, or to hand the icon off to your first screen, set an exit listener. You become responsible for removing the view:

Kotlin
splashScreen.setOnExitAnimationListener { provider ->
    provider.view.animate()
        .translationY(-provider.view.height.toFloat())
        .setDuration(300L)
        .withEndAction { provider.remove() }
        .start()
}

Forgetting provider.remove() leaves the splash covering your UI.

Migrate from a SplashActivity

Older apps usually had a dedicated launcher activity that showed a logo, waited, then started the real activity:

Kotlin
// The old pattern: do not copy this
class SplashActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)
        Handler(Looper.getMainLooper()).postDelayed({
            startActivity(Intent(this, MainActivity::class.java))
            finish()
        }, 3000)
    }
}

The fixed delay (or, in older versions, a Thread.sleep in a background thread) made every launch three seconds slower even when nothing was loading. On Android 12 and newer it also produces two splash screens in a row: the system one, then yours. To migrate:

  1. Move the LAUNCHER intent filter from SplashActivity to your main activity.
  2. Give the main activity the Theme.App.Starting theme and call installSplashScreen().
  3. Replace the delay with setKeepOnScreenCondition tied to work you actually need to finish.
  4. Delete SplashActivity and its layout.

If the splash activity also decided where to go (onboarding, login or home), keep that decision, but make it in the main activity after the splash ends, or use a navigation start destination chosen from the loaded state.

Testing it

The splash is easiest to see on a cold start. Stop the app first, then launch it again:

Shell
adb shell am force-stop com.example.app
adb shell am start -W -n com.example.app/.MainActivity

The -W flag also prints TotalTime, the time to the first frame, which is a useful number to watch as you add startup work. Test on an Android 12 or newer device and on an older one, since the compatibility library shows the static version there.

If the release build is next, the signed APK and app bundle tutorial covers building and installing it. A first-run flow after the splash often uses a ViewPager2 with dots. The platform reference is Splash screens on developer.android.com.

About Deshawn Schimme12 Articles
Android & Kotlin writer. Writes the Android and Kotlin tutorials: building, signing and shipping apps, and the Android APIs that replaced the old ways.