Android Splash Screen Tutorial with Example in Android Studio

Android Splash Screen is usually shown at start of the application for 2 or 3 seconds of time.

Main purpose of Android Splash Screen is to show logo and name of the application to user.

Sometimes it is also used for fetching required data from remote server before starting the app.

Splash screen is a simple screen or activity used to display some progress when application is launched.

Some developers use splash screen to just show company logo or to engage user while some important data in loaded in background.

After few seconds or minutes, splash screen is stopped and any other activity is started.

An Android app takes some time to to start up, especially when the app is first launched on a device.

A splash screen may display start up progress to the user or to indicate branding.

Latest purpose of splash screen can be found as you can ask for all permissions you are using in application.In all android versions after MARSHMALLOW, you have to request for permission to user. You can learn how to request for permission to user in this demo.

You can implement Splash Screen in many ways in Android. But I have shown easiest and quickest way to implement splash screen.

If you want some animation and cool effects in your splash screen, then visit following tutorials.

Following is the output of splash demo:

Step 1. Create new project

Create a new project in Android Studio with Empty Activity.

Step 2. Code for splash

Copy and paste following code in activity_main.xml file:

We have taken an ImageView with full size of screen.

You need to make a separate image for splash.

This image may contain company name and/or logo with or without  brand’s slogan.

Splash Image Size

You need to make different size of splash images for different android device screens.

There may be a small variations among various image sizes and screen sizes.

I am going to give you a dimensions which can be used generally in most of the cases.

  • LDPI:
    • Portrait: 200x320px
    • Landscape: 320x200px
  • MDPI:
    • Portrait: 320x480px
    • Landscape: 480x320px
  • HDPI:
    • Portrait: 480x800px
    • Landscape: 800x480px
  • XHDPI:
    • Portrait: 720px1280px
    • Landscape: 1280x720px
  • XXHDPI:
    • Portrait: 960px1600px
    • Landscape: 1600x960px
  • XXXHDPI:
    • Portrait: 1280px1920px
    • Landscape: 1920x1280px

Use images of above size for making your splash screen responsive among all the mobile and tablet devices.

Copy and paste following code in MainActivity.java

Introduction of HANDLER Class

The handler class lets you process and send message to other threads, which contain data, and runnable objects that belonging to a thread.

A handler will let you execute message objects and runnable objects at a specified time in the future.

Each instance of a handler will belong to a single thread only when declared.

Runnable objects are those objects that contain commands that will be executed to obtain results in your program.

To explain it to you plainly, a handler be used to execute a thread.

It will also allow various threads that make up a program to communicate with each other to prevent conflicts.

Explanation of MainActivity

We have used Handler class of JAVA to implement logic of Splash Screen.

  • A handler has a method called run().
  • In this run() method, you can write your required source code or give some instruction to your app.

Here in this example, I have tell my app to open WelcomeActivity.

  • Now with the help of Handler, you can delayed the execution of the code written in run() method.
  • You can give time duration in mili seconds to delay the execution of run() method.

In above example, I have taken 2000 mili seconds as delay.

I have used integer variable for this (SPLASH_DISPLAY_LENGTH).

  • Right now value of SPLASH_DISPLAY_LENGTH is 2000 milliseconds, which is equals to 2 seconds. You can change this time duration as per your requirements. (Increase this value to shown splash for more time otherwise decrease it.)
  • finish() method is written after starting a new activity. Splash screen is shown only at the opening of the app and when the user presses the back button to exit the app, splash screen should not be shown at that time.
  • For this purpose, finish() method will help us. It will remove the splash screen activity from the backstack so when the user presses back button, he will directly left the app.

Second Method

You can implement the splash screen with Thread class also.

Sample source code for using Thread is as the below source code

  • we are implementing a while() method in a thread.
  • I have declared one integer variable called waited. Value of waited is zero at the starting.
  • Value of waited is increased by 100 in the every iteration of the while loop.
  • when the value of waited variable is greater than SPLASH_DISPLAY_LENGTH , finally() method is called by the compiler.
  • In the finally() method, first activity of the android app is called.

To make splash screen with thread, replace the above code with the following code in our existing example

After making this changes you will be able to show the splash screen using thread.

If you want some animation and cool effects in your splash screen, then visit following tutorial.

Android Animated Splash Screen Tutorial With Source Code  

Related link:  Other ways to implement splash screen. 

How to get exact Android example while searching in Google

When you are learning new concepts in android app development, what do you do first? I guess you try to find that feature in google.

Now many times it happens that you enter search query for specific purpose but google gives you something else or may be it returned older tutorials with eclipse(which is already deprecated for android development) instead of android studio.

If you want to overcome these problems then visit below link, it will show you some techniques to solve these problems, which will save your lot of time and hard work as a result.

Visit this page for information.

Do consider to share our tutorials and examples with your friend and colleagues via social media.

Cheers and happy coding!

Download Code For Android Splash Screen

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

8 Responses

  1. Charles says:

    Simple yet quick code to make splash screen in easiest way. Good work!

  2. Peter says:

    Hello,I log on to your blog named “splash screen implementation in app using android studio” regularly.Your writing style is witty, keep up the good work!

  3. Kate Spade says:

    Good tutorials are there on this blog. Really nice work and keep going!

  4. Michael says:

    Great job Hardik!
    Very simple and nice article.

Leave a Reply

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