61

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.

Joseph Hawkes-Cates
  • 1,911
  • 2
  • 12
  • 13
  • Same, just tried out the new splash screen API on an Android 12 emulator, but too bad the icon is not showing, whether I set the "android:windowSplashScreenAnimatedIcon" or not, but the "android:windowSplashScreenBackground" is working though. Should we consider it as a bug? The API is not very friendly for older version of Android devices I think. – yao Nov 03 '21 at 03:31
  • Yeah, I think I'll try logging a bug to google and see what they say. – Joseph Hawkes-Cates Nov 03 '21 at 18:59
  • 9
    Well, I did figure out how to get it to show. I was following [this tutorial](https://medium.com/realm/explore-splashscreen-api-android-12-kotlin-7a8bf83b061a) 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 splash screen. You have to kill it and open the app from the app tray. Once I did that, I was able to see my splash screen. Annoying, but at least I have a way to test it now. – Joseph Hawkes-Cates Nov 03 '21 at 19:29
  • 2
    I went ahead and logged the bug report since this is confusing, but with my last comment, I have a way to test this now. Here's the bug report if anyone is curious: https://issuetracker.google.com/issues/205021357. – Joseph Hawkes-Cates Nov 03 '21 at 20:01
  • Having the same issue, doesnt seem like google have gotten around to investigating it yet. Hopefully soon. – AndroidDev123 Dec 28 '21 at 19:07
  • You should remove the `android` prefix if using the library – Vadim Caen Feb 09 '22 at 11:33
  • If running from Android Studio, the splash screen does not show properly, but if you launch the installed app from the launcher on the device you might see it works properly. That's how it was for my Google Pixel 4a which runs Android 12. – Andrew S Mar 25 '22 at 22:47
  • Still like that now a year later! – JPM May 25 '23 at 20:18

11 Answers11

115

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!

Joseph Hawkes-Cates
  • 1,911
  • 2
  • 12
  • 13
  • 9
    This issue was driving me insane. I followed Googles Guide on how to migrate and the other docs regarding the SplashScreen API. But on my Pixel I use Nova Launcher as desktop and you will never get the icon/images on the splash screen when launching the app from a shortcut or the drawer when using Nova Launcher. And still the same when launching with Android Studio. I only got the icon/images on the splash screen when I launched the app with the Pixel Launcher. So poorly done. – Gimberg Jan 18 '22 at 13:29
  • What does it mean to run an app from tray? Do you mean I must user the launcher on the phone? I think this needs rephrasing. – Andrew S Jan 25 '22 at 19:47
  • 8
    Geez, Android. Always good for a surprise. Looks like it is still buggy (well the lib is beta, so no surprise - however it is already enforced for api level 31) Thanks Joseph for the workaround, this already saved me a lot of time! However I can't access the bug report, is the link correct? And the issue with the other launcher as mentioned by @Gimberg is very annoying too. – Luzian Jan 28 '22 at 17:42
  • 1
    @AndrewS, yeah, I’m new to Android so still getting the right terminology down. Switched it to be launcher instead of app tray for clarity. – Joseph Hawkes-Cates Feb 06 '22 at 02:09
  • 1
    @Luzian, I got email updates for that bug report up until Jan 25th. I’m also getting access denied when I visit it now though so not sure what’s up there. – Joseph Hawkes-Cates Feb 06 '22 at 02:15
  • 2
    I found another report logged by someone else and it seems like Google is marking this as intended behavior… link for reference: https://issuetracker.google.com/199776339 – Joseph Hawkes-Cates Feb 06 '22 at 02:23
  • 1
    classic Googlers. It is driving me nuts, that things rarely works as described in docs...How they always find a way to screw something up, not make it properly, or buggy? – qkx Feb 08 '22 at 10:25
  • 1
    Half-baked API as always – Bitwise DEVS Apr 02 '22 at 20:46
  • This issue produced a lot of F's followed by a lot of U's in the last 40 minutes. – rexxar Oct 22 '22 at 13:03
  • 1
    absolutely right answer for me, i wasted 3Hr for this stupid issue of android – Rahul Mandaliya Jan 11 '23 at 13:20
  • Wasted a day on this thinking the app wasn't showing the splash icon... then I went down a rabbit and saw this. So stupid that it works on phone launcher but not from IDE launch! ugh – JPM May 25 '23 at 20:21
10

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

Muhammad Ahmed AbuTalib
  • 4,080
  • 4
  • 36
  • 59
  • This is a good catch. It would be nice if that documentation was directly on the installSplashScreen function instead of on SplashScreen class level or in this guide: https://developer.android.com/guide/topics/ui/splash-screen. I have no reason to reference the SplashScreen class directly unless I'm doing more sophisticated customization. Unfortunately, moving the installSplashScreen call to the right place still doesn't fix this issue. – Joseph Hawkes-Cates Feb 17 '22 at 20:00
  • Looking at the code, it seems like they recommend calling installSplashScreen before super.onCreate() because setContentView is called internally in super.onCreate() and the installSplashScreen doc does specify that it needs to be called before setContentView. It looks like that only applies if you are initializing your activity with a view ID instead of manually inflating the view. Since I'm using Compose I think as long as it's called before my setContent block, it's fine. Definitely doesn't hurt to move it before super.onCreate though. – Joseph Hawkes-Cates Feb 17 '22 at 20:10
  • no difference in my case – Palejandro Jul 11 '23 at 08:58
8

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>
Vadim Caen
  • 1,526
  • 11
  • 21
  • That is correct, but still, be aware of others said: the library is in alpha, so it's a little bit unstable. In most cases it works as expected, however, I've noticed that when I adb install the app that is already open, when I open it, the icon does not show. Also, I could not get the icon to work for API below 23. It works fine from API 23 and above. From the release notes, I guess that was expected: https://developer.android.com/jetpack/androidx/releases/core#core-splashscreen-1.0.0-alpha01 – rewgoes Nov 03 '21 at 15:19
  • Ok, that makes sense. I have tried it both with and without the "android:" prefix and it doesn't work on API 31 either way, though. It works fine on API 30, though. I'm a little surprised that it would be this sort of issue since the feature is new and designed for API 31 so that's the last place I expected to run into issues. – Joseph Hawkes-Cates Nov 03 '21 at 18:58
  • Vadim, please elaborate on exactly where we will use this. Name the resource file, manifest or other where this needs to go. As written this is very unclear. – Andrew S Jan 25 '22 at 19:46
  • This was in context of OP answer. I'll add some details to my answer – Vadim Caen Jan 27 '22 at 13:56
5

For some reason when the app is launched through android studio it doesn't show the icon. Kill the app and launch app from the menu. Then the icon will appear. This is true if you are not using Splash API: https://developer.android.com/develop/ui/views/launch/splash-screen/migrate

Ivan Kopylov
  • 71
  • 1
  • 3
5

In my case, the problem with the lack of a splash screen was the installation of the default activity theme:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:name=".App"
        android:theme="@style/Theme.Tracker.StartSplashScreen"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        tools:targetApi="tiramisu">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:theme="@style/Theme.Tracker">                 <-------
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

When I deleted android:theme="@style/Theme.Tracker" line, it started working.

mxkmn
  • 79
  • 1
  • 6
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 17 '23 at 06:36
3

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

3

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

Narendra_Nath
  • 4,578
  • 3
  • 13
  • 31
2

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>
Sakhawat Hossain
  • 454
  • 8
  • 23
2

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

Peter Akwa
  • 77
  • 1
  • 6
0

I had the same problem on my phone running Android 12. None of the above suggestions worked, (moving installSpashScreen() above super.onCreate etc...)

What fixed it for me was adding the android:theme attribute in the manifest to the Launching <activity> Tag, Not the <application> Tag, which is contrary to the documentation :

In the manifest, replace the theme of the starting activity to the theme you created in the previous step.

<manifest>
 <application android:theme="@style/Theme.App.Starting">
 <!-- or -->
     <activity android:theme="@style/Theme.App.Starting">

Note, you still have to kill the activity and launch it from the launcher for this to work :(

xidsyed
  • 1
  • 1
  • 1
-1

To @Gimberg above who said the icon doesn't display with Nova Launcher, thank you, I've spent a day trying to figure out why this wasn't working when it had been.

Dunny
  • 87
  • 1
  • 1
  • 13