Optimize Android Splash Screen

There is a long debate in support of having a Splash Screen in Android. But lets just consider WE HAVE A SPLASH SCREEN. So lets just implement it and lets implement it in the right way.

 


Conventional Layout for the Splash Screen design:

activity_splashscreen.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#C54E4E"
    android:gravity="center"
    android:orientation="vertical">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/splashicon" />

</LinearLayout>

But this implementation will create a small problem

 

issue-image


Optimizing Splash Screen:


Step 1: Create a custom drawable (instead of Layout):

splash_layer.xml

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

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

    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/splashicon">

        </bitmap>

    </item>

</layer-list>

 

Step 2: Create a separate theme Splash Activity:

styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="SplashScreenTheme" parent="AppTheme.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_layer</item>
</style>

AndroidManifest.xml

<activity
    android:name=".SplashScreen"
    android:theme="@style/SplashScreenTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

Step 3: Remove Layout from Splash Activity:

SplashScreen.java

public class SplashScreen extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // initialization code

        for (int i = 0; i < 2000; i++) {

        }

        startActivity(new Intent(this, MainActivity.class));
        finish();
    }
}

Optimize Splash Screen:

Leave a Reply