splashScreen.setOnExitAnimationListener() not called when using CustomSplashScreen with debugger

Viewed 1032

I'm using dependency "androidx.core:core-splashscreen:1.0.0-alpha01" for my splash screen. Using Android Gradle Plugin 7.0.1 (with Android Studio Arctic Fox 2020.3.1 Patch 1), Kotlin 1.5.20 and Java 11 setup in the IDE and for the project.

I use my own SplashActivity required for routing the user to different activities depending on the situation (doing anti-root checks, authentication checks etc).

My onCreate() has the following:

val splashScreen = installSplashScreen()
splashScreen.setOnExitAnimationListener { routeToOtherActivity() }

and I'm never calling setContentView().

Everything else is setup according to the migration guidelines:

https://developer.android.com/about/versions/12/splash-screen-migration

The problem is, when I run my app through Android Studio in debug mode the windowSplashScreenAnimatedIcon drawable set in the Theme.App.Starting theme is never shown and setOnExitAnimationListener is never called. So my application stays stuck in SplashActivity and the routing can never occur. When I run my app again using the app launcher manually, it runs as expected and both the drawable is visible and the routing is successful as the listener works as expected.

Is there any solution for this? Are there any open issues regarding this? (I couldn't find any)

I'm running the app on a physical device, Google Pixel 4 XL.

1 Answers

So if you don't call setContentView() the setOnAnimationExitListener will never be called since the activity doesn't draw. The splash screen is therefore never removed.

The fix is to remove the listener and call routeToOtherActivity() before installSplashScreen() and the behaviour will be as intended.

Source: https://issuetracker.google.com/issues/197906327

Related