SplashScreen

public final class SplashScreen


Compatibly class for the SplashScreen API introduced in API 31.

On API 31+ (Android 12+) this class calls the platform methods.

Prior API 31, the platform behavior is replicated with the exception of the Animated Vector Drawable support on the launch screen.

To use this class, the theme of the starting Activity needs set R.style.Theme_SplashScreen as its parent and the R.attr.windowSplashScreenAnimatedIcon and R.attr.postSplashScreenTheme` attribute need to be set.

Summary

Nested types

SplashScreen.Companion
SplashScreen.KeepOnScreenCondition

Condition evaluated to check if the splash screen should remain on screen

SplashScreen.OnExitAnimationListener

Listener to be passed in SplashScreen.setOnExitAnimationListener.

Public methods

final void

Sets the condition to keep the splash screen visible.

final void

Sets a listener that will be called when the splashscreen is ready to be removed.

Public methods

setKeepVisibleCondition

@NonNull
public final void setKeepVisibleCondition(
    @NonNull SplashScreen.KeepOnScreenCondition condition
)

Sets the condition to keep the splash screen visible.

The splash will stay visible until the condition isn't met anymore. The condition is evaluated before each request to draw the application, so it needs to be fast to avoid blocking the UI.

Parameters
@NonNull SplashScreen.KeepOnScreenCondition condition

The condition evaluated to decide whether to keep the splash screen on screen

setOnExitAnimationListener

@NonNull
public final void setOnExitAnimationListener(
    @NonNull SplashScreen.OnExitAnimationListener listener
)

Sets a listener that will be called when the splashscreen is ready to be removed.

If a listener is set, the splashscreen won't be automatically removed and the application needs to manually call SplashScreenViewProvider.remove.

IF no listener is set, the splashscreen will be automatically removed once the app is ready to draw.

The listener will be called on the ui thread.

Parameters
@NonNull SplashScreen.OnExitAnimationListener listener

The OnExitAnimationListener that will be called when the splash screen is ready to be dismissed.