Android Splash Screen Tutorial Using New Android Studio

51
1619
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.

0 0 vote
Article Rating
Subscribe
Notify of
guest

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

51 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Amir
Amir
5 years ago

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

Vamsi Tallapudi
5 years ago
Reply to  Amir

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

Abhijith
Abhijith
5 years ago

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

Vamsi Tallapudi
5 years ago
Reply to  Abhijith

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
Abhijith
5 years ago

Thanks I solved it!

Greg
Greg
5 years ago

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

Vamsi Tallapudi
5 years ago
Reply to  Greg

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

Web Stream
Web Stream
5 years ago

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

Oliver
Oliver
5 years ago

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
Jorge Américo Vargas Freitas
4 years ago
Reply to  Oliver

Good point: it helped me.

Roadrunner11
Roadrunner11
5 years ago

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

Rosh145
Rosh145
4 years ago
Reply to  Roadrunner11

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

TufaylAhmed
TufaylAhmed
4 years ago
Reply to  Rosh145

Did you manage to resolve this Isssue?

Vamsi Tallapudi
4 years ago
Reply to  Rosh145

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

Julio C Moreno
Julio C Moreno
5 years ago

Amazing This is the only tutorial that worked. Thank you

Vamsi Tallapudi
5 years ago
Reply to  Julio C Moreno

Glad to know.. Happy coding!

jerfesonguerreiro
jerfesonguerreiro
5 years ago

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

Vamsi Tallapudi
5 years ago

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

jerfesonguerreiro
jerfesonguerreiro
5 years ago

You’re welcome, it’s nice to help

Anar SAMADOV
5 years ago

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
Alfo Cancino
5 years ago

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

Ehtesham Hasan
Ehtesham Hasan
5 years ago

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
Mehmet Gunacti
5 years ago
Reply to  Ehtesham Hasan

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

Vamsi Tallapudi
5 years ago
Reply to  Ehtesham Hasan

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

Riley Hanson
Riley Hanson
5 years ago

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
5 years ago

Excelent post my friend. Congrats!

Vamsi Tallapudi
5 years ago
Reply to  Hammerfall357

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

gilson21
gilson21
5 years ago

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
5 years ago
Reply to  gilson21

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
Edward
5 years ago

Cool, works. Thanks!

King Alawaka
King Alawaka
5 years ago

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

Prince Chaudhri
4 years ago

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

Vamsi Tallapudi
4 years ago

Hi prince, Thank you. Glad to help you.

codexaddict
codexaddict
4 years ago

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
4 years ago

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

Ikram Mohammed
Ikram Mohammed
4 years ago

Thank you so much man!

Rosh145
Rosh145
4 years ago

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

David
David
4 years ago

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

Vamsi Tallapudi
4 years ago
Reply to  David

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

Jorge Américo Vargas Freitas
Jorge Américo Vargas Freitas
4 years ago

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

Let us see what can be done!

@rpit
@rpit
4 years ago

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

AndreiCh
4 years ago

Thank you. It was helpful.

nafees ahmed
nafees ahmed
4 years ago

Thanks

Shiraz Imam
Shiraz Imam
4 years ago

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

חנה קאהן
חנה קאהן
4 years ago

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

Jabi
3 years ago

I can’t download the file.

In manifest showing redline .SplasSreen and .MainActivity

In class folder

(R. Also red color

Help me

rushter
rushter
3 years ago
Reply to  Jabi

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

Tisco Idea
Tisco Idea
3 years ago

very nice tutorial!
Thank you!!!

Emily Carson
Emily Carson
3 years ago

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
ajay m v
3 years ago

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

Techy Rakshak
Techy Rakshak
3 years ago

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

what to do?
help