Create a splash screen in android

Splash screen is the welcome screen of the Android Application. Lunching when the user click the Application Launcher Icon.

The purpose of the splash screen

  1. Downloading data and storing in SQLite database.
  2. Downloading required images.
  3. Fetching and parsing JSON/XML.
  4. Sending device information/registering the device to our server.

Related Post

Custom dialog in android studio example

Get current speed using GPS android

Drag And Drop Listview Android


Steps to create a splash screen in android

1. Create the Layout with Image or with the Welcome Message.

splash_screen.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="@color/colorAccent">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/velmm_icon"
        android:background="@color/colorAccent"
        android:padding="50dp"/>

</LinearLayout>

2. Hide the Actionbar in SplashActivity before setContentView.

ActionBar actionBar = getSupportActionBar();
actionBar.hide();

3. Create a Handler and set that to run After particular Time Delay. Inside run() method call your MainActivity.java and finish the current SplashScreenActivity.

new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        // This method will be executed once the timer is over /
        // Start your app main activity
        Intent i = new Intent(SplashScreenActivity.this, MainActivity.class);
        startActivity(i);
        // close this activity
        finish();
    }
}, 3000);

Final SplashScreenActivity .java

public class SplashScreenActivity extends AppCompatActivity{

    private static int SPLASH_TIME_OUT = 3000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActionBar actionBar = getSupportActionBar();
        actionBar.hide();

        setContentView(R.layout.splash_activity);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                // This method will be executed once the timer is over /
                // Start your app main activity
                Intent i = new Intent(SplashScreenActivity.this, MainActivity.class);
                startActivity(i);
                // close this activity
                finish();
            }
        }, SPLASH_TIME_OUT);
    }
}

Screenshot

Splashscreen Android Example
Download

One Response

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to Top