Avid developer who has a passion for

Learn more about myself and what makes me so passionate about various forms of software development.

Gotcha when using Android's Splash API

Posted April 30, 2022 · 1 min read.

I've been extremely busy porting my company's Xamarin app into Native and something I decided to use was the compatibility library for Android's new Splash API for Android 12. This new Splash API is simply amazing and something that's been well overdue from Android, as before this, you had to roll your own and this new API sets some standards that were needed.

I however noticed an odd quirk and thought I'd share this here. When I went to run my app it died almost instantly with the following error:

You need to use a Theme.AppCompat theme (or descendant) with this activity.

but I was using the correct theme, so I re-read the migration guide and still got that message. I even created a bug report and that's when I realized what was causing this issue.

here is how I originally had the code:

override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?)
    val splashScreen = installSplashScreen()

    super.onCreate(savedInstanceState, persistentState)

    // Keep the splash screen visible for this Activity
    splashScreen.setKeepOnScreenCondition { true }

    // ... rest of my app's code

Running out of options I decided to just blindly try things and through that I figured out my problem. I realized I wasn't using persistentState and decided to remove that from onCreate() and just like that it was working.

Truthfully I don't know what persistentState is used for, but with that knowledge, I update said bug report so the folks working on this library can do their own research and replicate.

In short, if you happen to have persistentState set it's not going to work, you most likely don't need it, so it's not a giant loss.

If you do actually need it, then know it's not going to work with the Splash API compat library, at least for now.