Simple Splash screen on Android

Overview

Splash screen is the first screen of application. It often shows your logo, slogan  in a few seconds. I will introduce a simple way to implement Splash screen on Android application

1418337663850-2014-12-11 15.16.39

How to implement

Add SplashActivity.java

public class SplashActivity extends BaseActivity {
    private static final String TAG = SplashActivity.class.getSimpleName();

    private static final int TIME_TO_DISPLAY_SPLASH_SCREEN = 3000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.activity_splash);
        this.launchGreenFood();
    }

    private void launchGreenFood() {
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                goToMainScreen();
            }
        }, TIME_TO_DISPLAY_SPLASH_SCREEN);
    }

    private void goToMainScreen() {
        Intent intent = new Intent(this, MainActivity.class);
        super.startActivity(intent);
        super.finish();
    }
}

Add activity_splash.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher"/>
</RelativeLayout>

Declare SplashActivity  in manifest

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

In summary

This solution is easy way to implement Splash screen. You can add business login in SplashActivity such as: load database, init app, load data from server.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s