Jake Macale

Android Splash Screens the Right Way

Feb 18, 2021
1 minute

This implementation prevents RuntimeException due to the bitmap tag.

Let’s get started!

Picture 2

Drawable/bg_splash.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:drawable="@color/gray"/>

    <item
        android:drawable="@mipmap/ic_launcher_round"
        android:gravity="center"/>

</layer-list>

Styles

<style name="LaunchTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/background_launch</item>
</style>

AndroidManifest.xml

<activity
    android:name=".LaunchActivity"
    android:theme="@style/LaunchTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

LaunchActivity

class LaunchActivity : AppCompatActivity() {

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

        // Send user to MainActivity as soon as this activity loads
        val intent = Intent(this, MainActivity::class.java)
        startActivity(intent)

        // remove this activity from the stack
        finish()
    }
}

Enjoy your SplashScreen!

Picture 3