Tech Blog

Android

Handling Android 12 Splash Screen in existing projects

By Bvmg karthik2 min read
← Back to blog

Google introduced a new Splash Screen behavior in Android 12 and it will automatically generate a splash screen on the launch of any application. This is causing an issue of showing two splash screens for some applications where a splash screen is already implemented. One will be the system generated one and the other will be an app splash screen. 

We don’t have any API to remove the system generated splash screen and it is common behavior for all apps in Android 12. Now the only option to handle this issue is to remove the existing splash screen but it requires so much code refactor because it handles more complex scenarios such as performing app initialization and fetching data before the user is taken into the app.
So we can resolve this issue by Using some workarounds

Approach 1:
Add <item name=”android:windowIsTranslucent”>true</item> to your style

<style name="RemoveAppSplashTheme" parent="@style/AppBaseTheme">
<item name="android:windowIsTranslucent">true</item>
</style>

Apply this theme to your app splash screen Activity.

<activity
   android:name="com.app.SplashScreenActivity"
   android:theme="@style/RemoveAppSplashTheme"
   android:launchMode="singleInstance" />

This theme will replace the app default splash screen with a transparent screen. This will solve the two splash screen problem when the application has an existing splash screen.

If an application takes more time to load then this approach may look like the app is not responding because the system splash screen is invisible.

Approach 2:

We can suspend the application to draw an existing splash screen and show the system splash screen until the application is ready. This will solve the app delay problem

private void setupOnPreDrawListenerToRootView() {
   View pView = findViewById(android.R.id.content);
   pView.getViewTreeObserver().addOnPreDrawListener(
        new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
               // Check if the initialization is done or not.
               if (isAppInitialized) {
                   // The content is ready, then start main activity.
                   pView.getViewTreeObserver().removeOnPreDrawListener(this);
                   startActivity(new Intent(this, MainActivity.class));  
                   return true;
               } else {
                   // The content is not ready, then suspend.
                   return false;
               }
           }
       });
}

Once the app is ready we need to update the isAppInitialized to true, then we can remove the pre-draw listener and launch the MainActivity. Up to that point, it will hold the application to draw the present splash screen and execute all the app initializations.

Keep reading

You may be interested in

Browse all articles →
Android Download file with Data URL
July 23, 20241 min read

Android Download file with Data URL

What is a Data URL? Data URLs are the type of URL scheme that is used to embed usually small types of files. In this URL, inline files are prefixed with the data: MIME type. data:[<mediatype>][;base64],<data> To download files having Data URLs inside Android: Firstly, we need to get an extension of the file from […]

By Bansari PanditRead More →
Download the file with blob URL in Android WebView
July 23, 20242 min read

Download the file with blob URL in Android WebView

What is the Blob URL? Blob URLs can only be generated by the browser with use of internal mapping and used within the current document while it’s open which means it is valid for the same session (ie. the life of the page/document). The blob URL looks like this: blob:http://example.com/550e8400-e29b-41d4-a716-446655440000 Below is the sample HTML […]

By Bansari PanditRead More →
Key Terminologies in Android Enterprise
December 20, 20227 min read

Key Terminologies in Android Enterprise

Android Enterprise is a Google-led initiative to enable the use of Android devices and applications in a workspace. This program offers APIs and tools for developers to integrate support of Android devices into the EMM (enterprise mobility management) or UEM (Unified Endpoint Management) solutions. The following are the key terms associated with Android Enterprise. This […]

By Sandeep KadamRead More →