android splash screen

Android Splash Screen Tutorial Using New Android Studio

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.

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

  • Amir

    the application crached despite i add the right reference about my main Activity
    Can anyone help me

  • Make sure to use you typed .MAINACTIVITY in block letters in manifest file’s action tag

  • Abhijith

    Hey, I get the splash screen fine but after 3 seconds my main activity fails to start. Can u help?

  • There might be some typo in your Splash screen’s intent parameter (or) may be in your Main activity’s intent-filter’s action:name which is declared in your manifest. Intent takes action as its parameter. Here it is “com.coderefer.androidsplashscreenexample.MAINACTIVITY”. Make sure you match them exactly.

  • Abhijith

    Thanks I solved it!

  • Greg

    My splash screen works on my emulator but not on my device. Any idea why?

  • Web Stream

    Very very helpful man, tks for working on this tutorial. Work fine. <3

  • There may be some error in your package name. You may find this link useful: http://bit.ly/1Unw1OF

  • Oliver

    To get rid of the white screen that precedes the splash screen you might add:
    android:theme=”@android:style/Theme.Translucent.NoTitleBar”
    as an attribute within the activity tag for the splash screen activity.

    Not sure about compatibility with different API levels though.

    And of course: Thank you for the instructions!

  • Roadrunner11

    Thanks but after the splash screen is shown, my app crashes.

  • Julio C Moreno

    Amazing This is the only tutorial that worked. Thank you

  • jerfesonguerreiro

    finally{
    Intent i = new Intent(SplashScreen.this, MainActivity.class);
    startActivity(i);
    }
    this is better, and more compatible

  • Agreed. Thanks for the comment. Will update the code as its more helpful for reuse.

  • Glad to know.. Happy coding!

  • jerfesonguerreiro

    You’re welcome, it’s nice to help

  • Thanks for sharing. It is worked in android studio. In emulator i can see splash screen. but when i am trying at phone app works but splash screen not seen.

  • Alfo Cancino

    when I restart my application will not redisplay the splash D:

  • Marcos

    Thanks! For spanish people, here you can find a good tutorial: http://www.tutorialesandroid.net/splash-screen-en-android/

  • Ehtesham Hasan

    If my package name is com.example.game and main activity class name is AppActivity what will happen to this line in the manifest file?

  • Mehmet Gunacti

    I was wondering the same thing. why is MAINACTIVITY in capital letters here ?

  • Hi Hasan, you can give your name attribute as follows:
    “com.example.game.APPACTIVITY”

  • Riley Hanson

    If I am extending Activity what should the Activity class look like? My code is not compiling, because I have not created a savedInstanceState variable and InterruptException class. Can someone help me resolve where / how I should do those

  • Excelent post my friend. Congrats!

  • Thanks mate! more coming soon.. make sure to subscribe for latest posts and updates!

  • gilson21

    I got a confusion here with this line, in my mainfest.xml the code is as follows:

    so what will be the line of code in SplashScreen.java:

    finally{
    Intent openMainActivity= new Intent(“com.coderefer.androidsplashscreenexample.MAINACTIVITY”);
    startActivity(openMainActivity);
    }

  • Hi gilson, check the code from the explanation. You can use
    Intent i = new Intent(SplashScreen.this, MainActivity.class);
    Also you have mentioned the name property as android.intent.action.MAIN. This makes the main activity to launch first. Use a specific unique value such as

  • Edward

    Cool, works. Thanks!

  • King Alawaka

    awesome tutorial 😀 clean and simple works for me … thanks a lot buddy

  • Amazing:)
    You are awesome man, Thank u so much!

  • Hi prince, Thank you. Glad to help you.

  • codexaddict

    Hi Vamsi, thanks for your great tutorial. I am new to android app development, but with your explicit instructions to create a splash screen, I could easily create one and integrate into my app.

    However, I am facing a slight problem with the image. The splash screen shows my image with a vertical stretch. Is there any way I can rectify it ?

  • after implementing the splash screen i get two icons of my one app. Why this happen any solution ?

  • Ikram Mohammed

    Thank you so much man!

  • Rosh145

    Hi? Did you manage to solve your problem coz I have a similar one

  • Rosh145

    Hi? I have a slight problem, once the splashscreen is shown the app crashes…how do I fix it?

  • TufaylAhmed

    Did you manage to resolve this Isssue?

  • sharing the error from logcat will be helpful to know where it went wrong

  • David

    Hi.

    The app works great in my phone, but in Genymotion Emulator using Android Studio 1.5 (after importing your project) I get not splash screen with your logo, just a grey splash screen and fynally the main screen.

    Any idea about this behavior?
    Thanks for you work!!

  • Check for Splash screen image size.. It might be too large

  • Jorge Américo Vargas Freitas

    Thanks again, Vamsi: I am merging it with another tutorial by you.

    Let us see what can be done!

  • Jorge Américo Vargas Freitas

    Good point: it helped me.

  • @rpit

    What if i wanna to create dynamic splash screen like i wanna to fetch json data then after remove splash screen then??

  • Thank you. It was helpful.

  • nafees ahmed

    Thanks

  • Shiraz Imam

    I have 6 different splash screen for 6 different screen sizes(mdpi, hdpi, xhdpi etc) How can I display the respective splash screen?

  • חנה קאהן

    Thank you this was great!!!
    do you have a tutorial on search in listview of objects with customadapter?
    please….

  • I can’t download the file.

    In manifest showing redline .SplasSreen and .MainActivity

    In class folder

    (R. Also red color

    Help me

  • Tisco Idea

    very nice tutorial!
    Thank you!!!

  • Emily Carson

    Hi, on the spash.xml file im trying to add a imageView it acts like its there but its not showing up when i run it on emulator other than that it works perfectly

  • rushter

    change every instance of “com.coderefer.androidsplashscreenexample” to “com.yourcompany.yourappname” and that fixes it.

  • ajay m v

    i’m getting error in android:icon=”@mipmap/ic_launcher” how to fix it

  • Techy Rakshak

    sir, i am not getting option of java class.
    i m only gettin g option od c++ class

    what to do?
    help

  • Ahmad Dasoqe

    hello i have a little problem when i build my app and install it on my device
    the splash screen and the app are separated and i have two apps installed one with a splash screen and the other without.
    when i uninstall one of them the second is also deleted
    please help me

  • i have same problem

  • Ritikq Aggarwal

    Showing error R package does’n t exist . And showing unresolved class Main Activity in Android Manifest.xml file

  • jatin

    The app crashes every time I try to open it.