android splash screen

Android Splash Screen Tutorial Using New Android Studio

Vamsi Tallapudi Android, Programming 57 Comments

Android Splash Screen Example:

Many popular Android Apps such as Skype, Facebook, Adobe Reader, 500px, Dropbox etc.,  uses splash screen to display their logo. Most Android Apps uses Android Splash Screen before launching application Activity. Android splash screen is used to display a logo or brand for an app. In this article we are going to discuss about implementing an Android Splash Screen in a simple manner.

First we will create a new default project using these simple steps:

  1. Click on File > New Project.
  2. Next, define Application Name and Minimum SDK and hit Next
  3. Select Blank Activity and Hit Next.
  4. Hit Finish.

This creates a simple Hello world Project for which we will implement android Splash screen. We already discussed in detail about Creating New Android Project in our previous article.

android splash screen

Related Articles:

How to Test Android App on Real Devices like Android Mobile or Tablet using Android Studio

How to Test Android App on Emulator and setting up Android Virtual Device in New Android Studio

Creating Android Splash Screen:

  1. To display a splash screen, we need a layout first of all. So let’s create a Layout by Right Clicking on Layout (located in App > Res > Layout) and selecting New > Layout Resource File. Give it any name. I gave it splash.xml. Now select Text tab located at bottom as shown in image below. android splash screen example
  2. Now Open File Explorer in your Operating System and paste the image you want to use as splash screen in Drawable Folder. (Generally located  at C:\Users\UserName\AndroidStudioProjects\AndroidSplashScreenExample\app\src\main\res\drawable) . Advisable Image size is 800 x 1280 pixels and format is jpeg or png. Make sure that you named the image using small letters and underscores without using Special Symbols. I named it as splash_image.
  3. Now type the following code in Text Tab of splash.xml:
    Background is set to splash_image we just copied in Drawable folder. Here layout’s width and height are set to match_parent so that the background image fills the entire Layout.

  4. Splash screen is a separate activity which will be displayed first ahead of all other Activity. We create splash screen activity by creating a class. We create a new class by Selecting App > Java > Your Package Name and right Clicking on your package and selecting New > Java Class. Give it any name. Here, I gave it as SplashScreen. Now Type the Following Code in SplashScreen activity:

We use methods of Thread class such as –

sleep(long time) – to make the thread sleep for some time (in milliseconds).

start() – to start the thread.

sleep takes the time in milliseconds as its parameter(3000 => 3 seconds). Here we used this delay time as the time to display the splash screen activity. After this delay time, MainActivity is started by the code written in finally{} block.

The splash screen activity must not be shown when the user presses the back button. In order to do this, we should destroy the splash screen activity after it is shown for few seconds. This is done by the use of onPause() method. The onPause() method is a method of Activity class which comes into play when the user leaves the activity.

Next, We need to define which activity to open after displaying Splash screen. This is done using the Intent(Context, Class) constructor of the Intent class.

[wd_hustle id=”coderefer-email-optin-form”]

5. Now to make your splash screen to work, you need to refer the SplashScreen Activity in Android Manifest. So, open the Manifest file by clicking on App > Manifests > AndroidManifest.xml. Now we add reference to new Activity we just created and Change the Launcher Activity (Activity which Launches first) to splash.xml by changing the code shown below:

6. Now Hit Run Button (or Shift+ F10) and select Emulator or Real Device to run the program. Now you can see Android Splash Screen displaying before your activity.

You can refer to our previous articles on How to run android program on real Device and How to setup and test android project on Emulator for any reference.

Related Posts