What does windowSplashScreenAnimationDuration do?

Viewed 950

The splash screen API in Android introduced windowSplashScreenAnimationDuration . Has anyone noticed it having any effect over the splash screen duration or animation duration? Even I set it as recommended max of 1000ms, sometimes the splash screen is visible for less than that. If I set it to 100ms, the splash is visible for longer.

Furthermore, no matter how long my actual drawable (xml) animation is - the windowSplashScreenAnimationDuration seems to have no effect on it.

The documentation is pretty poor as well.

Can someone shed some light on this?

Thanks!

2 Answers

windowSplashScreenAnimationDuration has no direct effect on the duration. You retrive duration value using SplashScreenView#getIconAnimationDuration and use that value in your own business logic.

From https://developer.android.com/guide/topics/ui/splash-screen#suspend-drawing

Use windowSplashScreenAnimationDuration to indicate the duration of the splash screen icon animation. Setting this won't have any effect on the actual time during which the splash screen is shown, but you can retrieve it when customizing the splash screen exit animation using SplashScreenView#getIconAnimationDuration. See Keep the splash screen for longer periods in the following section for further details.

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    // ...

    // Add a callback that's called when the splash screen is animating to
    // the app content.
    splashScreen.setOnExitAnimationListener { splashScreenView ->
        // Create your custom animation.
        val slideUp = ObjectAnimator.ofFloat(
            splashScreenView,
            View.TRANSLATION_Y,
            0f,
            -splashScreenView.height.toFloat()
        )
        slideUp.interpolator = AnticipateInterpolator()
        slideUp.duration = 200L

        // Call SplashScreenView.remove at the end of your custom animation.
        slideUp.doOnEnd { splashScreenView.remove() }

        // Run your animation.
        slideUp.start()
    }
}


// Get the duration of the animated vector drawable.
val animationDuration = splashScreenView.iconAnimationDuration
// Get the start time of the animation.
val animationStart = splashScreenView.iconAnimationStart
// Calculate the remaining duration of the animation.
val remainingDuration = if (animationDuration != null && animationStart != null) {
    (animationDuration - Duration.between(animationStart, Instant.now()))
        .toMillis()
        .coerceAtLeast(0L)
} else {
    0L
}

At this time, androidx.core:core-splashscreen is 1.0.0-alpha01.

It seems windowSplashScreenAnimationDuration value is only used for v31 android:windowSplashScreenAnimationDuration.

https://android.googlesource.com/platform/frameworks/support/+/049995bd740483b4742affb9095889fb8bb9a735/core/core-splashscreen/src/main/res/values-v31/styles.xml#23

    <item name="android:windowSplashScreenAnimationDuration">
       ?windowSplashScreenAnimationDuration
   </item>

So, windowSplashScreenAnimationDuration has no effect before android 12 platform. The value has effect only android 12 (and over).

Related