3

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).

hata
  • 11,633
  • 6
  • 46
  • 69
Zeeshan Ahmed
  • 43
  • 1
  • 4
  • See my answer at https://stackoverflow.com/questions/67921860/disable-android-12-default-splash-screen/68016634#68016634 – Vadim Caen Jun 24 '21 at 20:26
  • Does this answer your question? [Disable Android 12 default splash screen](https://stackoverflow.com/questions/67921860/disable-android-12-default-splash-screen) – Vadim Caen Jul 20 '21 at 16:52

3 Answers3

9

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.

  • 2
    This will actually just leave the splash screen visible until the app is initialized, it won't prevent the splash screen from showing. The splash screen is not drawn by the app, but by the system, and the system waits for the app to draw before dismissing the splash screen. – Vadim Caen Jul 20 '21 at 16:51
  • worked like a charm. Thanks :) – dennisrufigill Jan 11 '22 at 07:30
0

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.

Shlomi Katriel
  • 2,103
  • 1
  • 7
  • 20
0

As per official Document we can customise default splash screen of Android 12 and higher versions, Or you can Migrate your existing splash screen implementation to Android 12 and higher, i have used following steps to customise my apps splash screen

Step 1 : Add below gradle line in build.gradle (App level) and Sync Now

implementation 'androidx.core:core-splashscreen:1.1.0-alpha01'

Setp 2 : Add below lines of code to your themes.xml

 <style name="Theme.App.Starting" parent="Theme.SplashScreen">
    <!-- Set the splash screen background, animated icon, and animation duration. -->
    <item name="windowSplashScreenBackground">@android:color/transparent</item>
    
    <item name="windowSplashScreenAnimationDuration">50</item>

    <!-- Set the theme of the Activity that directly follows your splash screen. -->
    <!-- Required -->
    <item name="postSplashScreenTheme">@style/Theme.Your_App_Name</item>
</style>

Step 3 : Now apply "Theme.App.Starting" theme in splash screen from manifest.xml, after apply theme code will be look like below

<activity
        
        android:theme="@style/Theme.App.Starting"
        android:name=".Splash"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

Step 4 : Now add below line of code to Splash screen activity in onCreate() method before super.onCreate(savedInstanceState);

SplashScreen.installSplashScreen(this);

After add above code in your splash screen activity onCreate() mwthod will be look like this

 @Override
protected void onCreate(Bundle savedInstanceState) {
    SplashScreen.installSplashScreen(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
}

Now default splash screen customised

Note : I have answered of this question in Java, you can convert these lines of codes in kotlin

Happy coding.

Basant
  • 741
  • 7
  • 16