Android 12 Splash Screen Icon Not Displaying

Viewed 13751

I am seeing a weird issue with a new app that I am starting. I am utilizing the new Android 12 splash screen API to create my splash screen and I followed the guide provided by Google to do so. I included core-splashscreen in my project to provide compatibility with older versions of Android OS. When I run the app, I see the splash screen as expected on older OS versions like API 30, but when I run it on API 31, the splash screen icon that I provide is not displayed. The background color that I specify is displayed, but the icon is not there at all. I have tried this with a drawable asset as well as a mipmap and nothing is working. I am stumped as every tutorial I find shows the same steps I have followed and screenshots of their working splash screens, but I am not having any luck.

For context here is my splash screen style definition for v31:

<style name="Theme.Splash" parent="Theme.SplashScreen">
    <item name="android:windowSplashScreenBackground">@color/orange_7A</item>
    <item name="android:windowSplashScreenAnimatedIcon">@drawable/splash_foreground</item>
    <item name="postSplashScreenTheme">@style/Theme.App</item>
</style>

I have an identical style for all other OS versions except I'm using "windowSplashScreenAnimatedIcon" instead of "android:windowSplashScreenAnimatedIcon". I have tried v31 with and without the "android:" in front of the item names and neither work. Here is my MainActivity.kt:

class MainActivity : AppCompatActivity() {

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

    installSplashScreen()
    
    setContent {
        MyVeevaTheme {
            Login()
        }
    }
}

I am also setting the "android:theme" property to my splash style in my AndroidManifest.xml. I know the splash style is being applied because it honors the background color, but it is not showing the icon for some reason even though the icon shows fine for older OS versions. Thanks in advance for any help you can give.

8 Answers

TL;DR kill the app and run from the launcher, icon does not show up when run from Android Studio.

Adding my comment here as an answer for better visibility.

I did figure out how to get it to show. I was following this tutorial to set up a base project to recreate the issue and I noticed the note the author put right near the bottom that mentions that just running the app doesn't show the full splash screen. You have to kill it and open the app from the launcher. Once I did that, I was able to see my splash screen. Annoying, but at least I have a way to test it now. I did go ahead and log a bug report for this as well, but I have a work around for now. Thanks for everyone's answers/comments!

When you use the AndroidX SplashScreen Library, like you are doing (Theme.SplashScreen) you need to use the windowSplashScreen* attributes without the android: prefix.

The android: prefix is used to call the platform attributes, but in this case you are using the library and not the platform, so no need for the prefix:

res/values/themes.xml:

<style name="Theme.Splash" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/orange_7A</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/splash_foreground</item>
    <item name="postSplashScreenTheme">@style/Theme.App</item>
</style>

folks as per the document installSplashScreen() should have been called prior to super.onCreate()

Icons are also not shown when navigating from the deeplink. And It looks like its more then only not showing the icon. It also stops calling code for setOnExitAnimation lambda.

installSplashScreen().apply {
    setOnAnimationListener { viewProvider ->
    viewProvider.iconView
    .animate()
    .setDuration(500L)
    .alpha(0f)
    .withEndAnimation {
       viewProvider.remove()
       someActionCall() 
    }
    .start()
} 

If you relied upon this code to be always called it is not. See mention in issue tracker: https://issuetracker.google.com/issues/207095799

The following instructions helped me, you may try this one. A few things need to keep in mind while working with the new splash screen API.

  1. Keep updated on the latest library version. Follow this link (https://developer.android.com/jetpack/androidx/releases/core).
  2. Put installSplashScreen() before setContentView()
  3. Make a proper theme for the splash screen. You may try the following one.

Put this into your styles.xml or themes.xml folder and use it with your activity as the theme.

 <!-- Splash Screen Theme. -->
<style name="Theme.AppSplash" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/white</item>
    <item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher_round</item>
    <item name="windowSplashScreenAnimationDuration">1000</item>
    <item name="postSplashScreenTheme">@style/AppTheme</item>
</style>

Make sure you set the theme to the MainActivity as well. For me that was the cause for the splash screen to now show. So you have to set the theme in both the application and the MainActivity

In addition to the other explanations above, I had the same issue but I realized that in my Manifest file I was setting the Splashscreen theme on my MainActivity which is correct, but my MainActivity was not having the main/launcher intent-filter which tells the android OS that this is the starting activity.

<intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

So in your manifest, check that you are actually setting the Splashscreen theme on the Starting activity that is having the main/launcher intent-filter, and leave the Application tag to have your application theme and not the Splashscreen theme, to avoid having your app misbehave on other activities due to the theme because I experienced that too (This is especially for those migrating to the new splash screen).

Thank you, I hope someone finds this helpful

Related