Android Splash Screen Tutorial Using New Android Studio

51
57
android splash screen

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.[widget id=”text-3″]
  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.

[widget id=”text-3″]

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.

51
Leave a Reply

avatar
33 Comment threads
18 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
37 Comment authors
Techy Rakshakajay m vrushterEmily CarsonTisco Idea Recent comment authors

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
newest oldest most voted
Notify of
Amir
Guest
Amir

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

Vamsi Tallapudi
Guest

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

Abhijith
Guest
Abhijith

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

Vamsi Tallapudi
Guest

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
Guest
Abhijith

Thanks I solved it!

Greg
Guest
Greg

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

Vamsi Tallapudi
Guest

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

Web Stream
Guest
Web Stream

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

Oliver
Guest
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!

Jorge Américo Vargas Freitas
Guest
Jorge Américo Vargas Freitas

Good point: it helped me.

Roadrunner11
Guest
Roadrunner11

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

Rosh145
Guest
Rosh145

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

TufaylAhmed
Guest
TufaylAhmed

Did you manage to resolve this Isssue?

Vamsi Tallapudi
Guest

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

Julio C Moreno
Guest
Julio C Moreno

Amazing This is the only tutorial that worked. Thank you

Vamsi Tallapudi
Guest

Glad to know.. Happy coding!

jerfesonguerreiro
Guest
jerfesonguerreiro

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

Vamsi Tallapudi
Guest

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

jerfesonguerreiro
Guest
jerfesonguerreiro

You’re welcome, it’s nice to help

Anar SAMADOV
Guest

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
Guest
Alfo Cancino

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

Ehtesham Hasan
Guest
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
Guest
Mehmet Gunacti

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

Vamsi Tallapudi
Guest

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

Riley Hanson
Guest
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

Hammerfall357
Guest

Excelent post my friend. Congrats!

Vamsi Tallapudi
Guest

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

gilson21
Guest
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);
}

Vamsi Tallapudi
Guest

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
Guest
Edward

Cool, works. Thanks!

King Alawaka
Guest
King Alawaka

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

Prince Chaudhri
Guest

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

Vamsi Tallapudi
Guest

Hi prince, Thank you. Glad to help you.

codexaddict
Guest
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 ?

Murtaza Panhwar
Guest

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

Ikram Mohammed
Guest
Ikram Mohammed

Thank you so much man!

Rosh145
Guest
Rosh145

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

David
Guest
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!!

Jorge Américo Vargas Freitas
Guest
Jorge Américo Vargas Freitas

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

Let us see what can be done!

@rpit
Guest
@rpit

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

AndreiCh
Guest

Thank you. It was helpful.

nafees ahmed
Guest
nafees ahmed

Thanks

Shiraz Imam
Guest
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?

חנה קאהן
Guest
חנה קאהן

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

Jabi
Guest

I can’t download the file.

In manifest showing redline .SplasSreen and .MainActivity

In class folder

(R. Also red color

Help me

rushter
Guest
rushter

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

Tisco Idea
Guest
Tisco Idea

very nice tutorial!
Thank you!!!

Emily Carson
Guest
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

ajay m v
Guest
ajay m v

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

Techy Rakshak
Guest
Techy Rakshak

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

what to do?
help