Remove default Splash Screen from Android 12 (Example)

Viewed 4033

Latest Beta version of Android SDK showcasing Default Splash Screen on every app running on Android 12 (Emulator), As per the requirements, we already have our own Splash Screen.

If anyone have worked on it, let me know how to disable/remove it (preferred to have and example code).

2 Answers

There is no direct API to disable the default splash screen but we can handle this with some workarounds.

Approach 1:

Add <item name="android:windowIsTranslucent">true</item> to your style

<style name="Theme.RemoveSplashScreenTheme" parent="@style/BaseTheme">
    <item name="android:windowIsTranslucent">true</item>
</style>

Apply this to splash screen Activity.

<activity
        android:name="com.test.SplashScreenActivity"
        android:launchMode="singleInstance"
        android:theme="@style/Theme.RemoveSplashScreenTheme"
        android:noHistory="true" />

this will replace the default splash screen with a transparent screen. This workaround will eliminate the 2 splash screen issue if the app already has one.

But it will make the system splash screen invisible and it may look like the app is not responding. If anyone facing this issue then follow the next workaround.

Approach 2:

So we can resolve this issue by suspending the app to draw an existing splash screen and show the system splash screen until the app is ready.

private void setupOnPreDrawListenerToRootView() {
  View mViewContent = findViewById(android.R.id.content);
  mViewContent.getViewTreeObserver().addOnPreDrawListener(
       new ViewTreeObserver.OnPreDrawListener() {
           @Override
           public boolean onPreDraw() {
               Log.v("onPreDraw","onPreDraw called");
               if (isAppInitialized) {
                    mViewContent.getViewTreeObserver().removeOnPreDrawListener(this);
                    startActivity(new Intent(this, MainActivity.class));

                   return true;
               } else {
                   // The content is not ready; suspend.
                   return false;
               }
           }
       });
}

Here we need to update isAppInitialized to true once the app is ready then we can remove the listener and launch the MainActivity until then it will hold the. app to draw an existing splash screen and execute all the app initializations.

I believe it’s impossible, though I very hope I’m wrong.

The docs does not mention anything about disabling it and it’s automatically being added to all apps.

I’m running Android 12 beta 2.1 on my Pixel 5 device and a lot of my apps have double splash screen because of it.

I recommend giving up migrate your code to the new API and make sure your code is compatible for Android 11 devices and below.

Related