New Splash Screen In Android

Narayan Panthi
Nerd For Tech
Published in
4 min readMay 15, 2021

--

A better way to display Android Splash Screen.

🚣 In this article, we learn how to implement splash screen on Android. From the old traditional to the new modern way.

Android Splash Screen usually the first screen that is displayed to the user when an app is not fully ready to display content.

How Splash Screen Works

When a user launches an app while the app’s process is not running (a cold start) or the Activity has not been created (a warm start), the following events occur. (The splash screen is never shown during a hot start.)

  1. The system shows the splash screen using themes and any animations that you’ve defined.

2. When the app is ready, the splash screen is dismissed and the app is displayed.

Now let's dive in,

Initializing Splash Activity

First, To launch the activity as splash screen we just need to add the action main and category launcher to your activity in AndroidManifest.xml

<activity
android:name=".ui.splash.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Traditional Way

We used to pause the user interaction for like 2–3 seconds for a splash screen to load.

UI Holding was never an option. As in Activity we used to write these horrific code… and activity used to work and look like shi**.

The Waiting Screen

This used to work well back then & now too, but we all knew there should be something more than just waiting.

Modern Approach

With a new approach, we don’t declare a time to wait.

Let's create a drawable background for placing the logo as a bitmap or drawable, depending on the available logo type.

drawable/background_splash.xml

In style, declare any desired theme for the splash screen and set android:windowBackground attribute value for the drawable we created.

<style name="SplashScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryVariant">@color/colorSecondary</item>
<item name="colorOnPrimary">@color/colorWhite</item>
<item name="android:windowBackground">
@drawable/background_splash</item
</style>

The android:windowBackground attribute will show our created drawable on the activity transition.

And, in AndroidManifest.xml we add our theme.

<activity
android:name=".ui.splash.SplashActivity"
android:launchMode="singleTask"
android:theme="@style/SplashScreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Finally,

To hide the content of the splash screen layout, in activity remove s̶e̶t̶C̶o̶n̶t̶e̶n̶t̶V̶i̶e̶w̶(̶)̶;

public class SplashActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// s̶e̶t̶C̶o̶n̶t̶e̶n̶t̶V̶i̶e̶w̶(̶)̶;
doFirstRunCheckup();
}

private void doFirstRunCheckup() {
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}

}

And Done. The modern approach is more convincing than our traditional approach.

New Splash Screen API

From Android 12 the newSplashScreen API is available, which enables a new app launch animation for all apps. This includes an into-app motion at launch, a splash screen showing your app icon, and a transition to your app itself.

Before proceeding, it’s important to confirm that the launch screen is set to “exported = true” to enable it to receive intents from external sources.

<activity
android:name=".ui.main.MainActivity"
android:exported="true">
//...

</activity>

Let’s add the dependencies for the new Splash Screen API.

    implementation 'androidx.core:core-splashscreen:1.0.1'

Then, we have to define themes for our Splash Screen.


<!-- themes.xml - Splash application light theme. -->
<style name="Theme.FireflyCompose.Splash" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/splash_background_light</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
<item name="postSplashScreenTheme">@style/Theme.FireflyCompose</item>
<item name="android:statusBarColor">@color/white</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:windowLightNavigationBar" tools:ignore="NewApi">true</item>
<item name="android:dialogTheme">@style/Theme.DialogFullScreen</item>
</style>

<!-- night/themes.xml - Splash application dark theme. -->
<style name="Theme.FireflyCompose.Splash" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/splash_background_dark</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
<item name="postSplashScreenTheme">@style/Theme.FireflyCompose</item>
<item name="android:statusBarColor">@color/black</item>
<item name="android:windowLightStatusBar">false</item>
<item name="android:windowLightNavigationBar" tools:ignore="NewApi">false</item>

</style>

To place your splash launcher icon and background, we can use these attributes.

<item name="windowSplashScreenBackground">@color/splash_background_light</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>

Also, we can define postSplashScreenTheme which will automatically provide a new theme for our app after splash screen is completed.

<item name="postSplashScreenTheme">@style/Theme.FireflyCompose</item>

Then, we have to define the theme of our activity.

 <activity
android:name=".ui.main.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize"
android:theme="@style/Theme.FireflyCompose.Splash" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

Finally , we can add a splash screen to the activity as follows:

 installSplashScreen().apply {
// adding loading condition
setKeepOnScreenCondition {

return viewmodel.isFetchedResources // true
}
}
@AndroidEntryPoint
class MainActivity : ComponentActivity() {

private val TAG: String = AppLog.tagFor(this.javaClass)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen()
}
}

To customize it more, read the Official Doc

You’re not required to use any specific splash screen; feel free to choose the one you prefer. However, it’s worth noting that the new splash screen comes highly recommended for its numerous benefits, including improved app opening speed.

Thank you.

Goodbye & Meow 😸

--

--