Android: Splash Screen with Kotlin
Tags: android, kotlin, learning
Published: 2018-08-03 18:18:43

---
title: Android: Splash Screen with Kotlin
published: true
description: There are different opinions on whether having a splash screen on your Android application or not.
tags: android, kotlin, learning
canonical_url: https://isscroberto.com/2018/06/08/android-splash-screen-with-kotlin/
cover_image: https://isscroberto.files.wordpress.com/2018/06/pineapple-at-the-beach_925x.jpg
---

There are different opinions on whether having a splash screen on your Android application or not.

Personally, I think splash screens are a good place where you can showcase your app's nice design and give your users a good first impression.

So, this is how I've been implementing splash screens on my recent Android apps with Kotlin.
<h2>Static vs Animated</h2>
I've used both static and animated splash screens and here are some thoughts.
<h3>Static</h3>
<ul>
	<li>Showed only in the launching of your app before onCreate() is called.</li>
	<li>You're not wasting your users time.</li>
	<li>Not intended to run operations while the splash screen is shown.</li>
</ul>
<h3>Animated</h3>
<ul>
	<li>You can show a cool animation and custom design.</li>
	<li>Flexibility to perform some operations while the animation finishes.</li>
	<li>Users can get bored if the animation is useless or if it takes too long.</li>
</ul>
<h2>Static Android Splash Screen</h2>
<img class="  wp-image-305 aligncenter" src="https://isscroberto.files.wordpress.com/2018/06/one-breath-splash.gif" alt="one-breath-splash" width="300" height="533" />
<h3><strong>1.</strong></h3>
Create the drawable file that we will use as background in the entry activity, by using a background, the app will show it without having to inflate a layout file.

{% gist https://gist.github.com/robertoissc/398df455ed7c60abf0c6de75783e0e09.js %}

<h3>2.</h3>
Create a theme in the styles file with no action bar that uses the splash drawable as the background to set it in the entry activity.

{% gist https://gist.github.com/robertoissc/d0a0a7a6291deeebfc6b905dbc6977f6 %}

<h3>3.</h3>
Set the new style as a theme for the splash activity in your app manifest.

{% gist https://gist.github.com/robertoissc/ab4d4a68c780cd036cc1151a21429172 %}

<h3>4.</h3>
Add the code to navigate to the next activity as soon as the app has finished loading.

{% gist https://gist.github.com/robertoissc/cefad910a3863e1cccf2e655ef7b134f %}

<h2>Animated Android Splash Screen</h2>
<img class="  wp-image-306 aligncenter" src="https://isscroberto.files.wordpress.com/2018/06/power-nap-splash.gif" alt="power-nap-splash" width="300" height="533" />

When I use animated splash screens I like to keep showing the static part of the splash screen on the initialization so I repeat steps 1, 2 and 3 from above and just add the animation functionality.
<h3>4.</h3>
For the animated splash screen, we will inflate a layout with the element or elements we want to animate. In this case, I'm just animating a textview.

{% gist https://gist.github.com/robertoissc/6a4cc97a858125e57deb569312eda374 %}

<h3>5.</h3>
Now we need to modify the splash activity to enable the animation and perform some loading operations in the meantime. Here's how my splash activity looks like.

{% gist https://gist.github.com/robertoissc/6ebe69d7b49f5c5f3536a2bd102cbebd %}

That's it, please share your thoughts on Android splash screens and your comments on how to improve this implementation.