Fast Splash Screen in Android

In this tutorial, I am focusing on Splash screen. A splash screen is majorly used in any app. But most importantly How we can make splash screen to load fast. I have seen some of the apps like Flip-cart,  they used this kind of splash screen.

So I thought it good to share with all of you. In earlier, we used to set the layout on Activity. In this case, I found that it takes little bit time to load. In between while loading the splash It shows black background for a while of time. So I think it makes the wrong impression for the user to show a black background for a while.

Here is uploaded video to check how fast loading splash. Please check this.


Let's make a fast loading splash screen without setting any layout on Activity. We can achieve this by using style. We can set the style on activity Manifest.

splash_background.xml

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

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

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

    </item>

</layer-list>

style.xml

    
<style name="Splash" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:windowBackground">@drawable/splash_background</item>
</style>

MainApplication.java

    
public class MainApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        SystemClock.sleep(1500);
    }
}

AndroidManifest.xml

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

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


Thanks for reading this article. 

No comments:

Post a Comment

Debug Database in Android

In my last tutorial, we have learned how we can use persistence database in android. We also understood which database wrapper we can use...

Contact Me

Name

Email *

Message *