HomeAndroidImplement Default Splash Display Previous to Android 12

Implement Default Splash Display Previous to Android 12


In case your app does not implement any splash display screen, it’s carried out by default in Android 12 (API stage 31). In different phrases, there’s a splash display screen for Android 12 or later however not for Android 11 and older Android model.

Implement Default Splash Screen Prior to Android 12 01.gif

To remain in step with the older Android model to have an identical default splash display screen, you may observe this step-by-step information to implement the splash display screen.

1. Add Splash Display Library

Add androidx.core:core-splashscreen library in construct.gradle.

dependencies {
   implementation 'androidx.core:core-splashscreen:1.0.0'
}

2. Add Splash Display Type

Add this splash.xml in your res/values folder. It may be any title you want. You can even use the prevailing themes.xml if in case you have it.

<assets>
    <type title="Theme.App.Beginning" mum or dad="Theme.SplashScreen">
        <merchandise title="windowSplashScreenBackground">#ff616161</merchandise>
        <merchandise title="windowSplashScreenAnimatedIcon">@drawable/ic_android_kotlin_weekly</merchandise>
        <merchandise title="postSplashScreenTheme">@android:type/Theme.Materials.Mild.NoActionBar</merchandise>
    </type>
</assets>
  • Set the theme type mum or dad to Theme.SplashScreen

  • Set windowSplashScreenBackground to your app major colour

  • Set windowSplashScreenAnimatedIcon to your app icon asset

  • Set postSplashScreenTheme to your unique theme type on your app

Please be aware that I exhausting code the colour as a substitute of utilizing @colour/... as a result of I’ve gotten rid of this colours.xml fully on this clear compose app template.

In reality, I feel we should not have to have this splash.xml in any respect for Jetpack Compose app.

3. Replace Utility Theme Type

In AndroidManifest.xml, replace software android:theme

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <software
        android:theme="@android:type/Theme.Materials.Mild.NoActionBar">
    </software>
</manifest>

with @type/Theme.App.Beginning that you just created in splash.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <software
        android:theme="@type/Theme.App.Beginning">
    </software>
</manifest>

4. Name installSplashScreen() in Exercise

In your exercise, name the installSplashScreen(), earlier than you name the Acitivty.onCreate() base class.

To determine how lengthy the splash display screen keep, you may name SplashScreen.setKeepOnScreenCondition() which lets you implement KeepOnScreenCondition interface utilizing SAM conversion.

That is an instance of what I did for my rss feed reader app

    override enjoyable onCreate(savedInstanceState: Bundle?) {

        setupSplashScreen()

        tremendous.onCreate(savedInstanceState)
        
    }

    personal enjoyable setupSplashScreen() {
        var keepSplashScreenOn = true
        lifecycleScope.launch {
            lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
                viewModel.uiState.acquire 
            }
        }

        installSplashScreen().setKeepOnScreenCondition {
            keepSplashScreenOn
        }
    }

Abstract

Your app now ought to have the splash display screen in all Android variations. It is a default splash display screen implementation which is fairly easy. For extra particulars, you may discuss with this official information.

If the splash display screen does not work, you could wish to make certain your app is totally killed as a result of the splash display screen is NOT proven throughout sizzling begin. This appears to occur in API 33 the place urgent the again button does not kill the app. It’s nonetheless within the background.

Reference

Code Modifications Instance: Diff(Android Information) and Diff(Template App)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments