In this post I’ll explain how to create a really bare-bones splash screen for an Android screen. I’ll be assuming that you don’t know very much at all about Android development, so we can simulate my experience with this. I’ll also be assuming that you’ve set your environment up for Android development per Google’s basic documentation.
Creating the Basic Android Project
Go to File –> New –> Android Project, and enter your defaults as below.
Click Finish. In the Package Explorer, expand the SplashScreenSample –> src node until you can see all the children.
Double click the onCreate(Bundle) : void node to view the source code in Eclipse.
This is the default activity that launches when your application starts up. To verify, run the project by clicking on the Run –> Run menu option, then selecting the Android Application option.
After some time spinning up, you’ll see your app running in the emulator. This is essentially the Hello World app, but I put the steps in here just in case you’re new to Android development and Eclipse in general. I was, and this kind of walkthrough would have helped a lot.
Adding a Screen
The first thing we need to do is add another screen to the project, which will be what we display after the splash screen has run its course. The first step in adding a screen is to add an activity to the Android Manifest. First, double-click the AndroidManifest.xml file.
Click the Application tab at the bottom.
We need to add another Activity to our application, so click the Add button in the bottom half of the screen, in the Application Nodes section. Select Activity and click Ok.
You’ll see a whole slew of options for your new Activity. Let’s just name it mainmenu with a Launch mode of standard. Notice that when we enter a name for our activity, Eclipse complains to us that there is no matching class.
Let’s rectify this by adding a class called mainmenu to our application. Right click on the src node in the Package Explorer and select New –> Class. Call the class mainmenu and click Finish. Then add code to your mainmenu class to make it appear as below.
package com.testing.splashscreensample; import android.app.Activity; import android.os.Bundle; public class mainmenu extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
Now we have the screen that we will show after our splash screen finishes displaying.Finishing Up The Splash Screen
Our next step is to add the image you want the splash screen to show. Pick whatever image you want to be displayed as the splash screen, and copy it into the three drawable-* directories under the res node in your project. You can use Explorer-like functionality to do this.
Next we need to define the layout for our splash screen. We start by expanding the res node in Package Explorer, right clicking on the res –> layout node and selecting Android XML File. Call the file splash.xml and click on Finish.
Open up the splash.xml file by double-clicking it and ensure that the xml itself looks like the below. You can see the actual xml in the file by clicking the splash.xml tab.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:src="@drawable/thumbsup" android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content"> </ImageView> </LinearLayout>We’ve basically added an ImageView control that is pointing to the image we just added to our project, via the android:src attribute on the tag element.
The last step is to add code to the SplashScreen class file. Double click the SplashScreen.java node and copy and paste the below code into the file.
package com.testing.splashscreensample; import android.app.Activity; import android.content.Intent; import android.os.Bundle; public class SplashScreen extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); Thread splashThread = new Thread() { @Override public void run() { try { int waited = 0; while (waited < 5000) { sleep(100); waited += 100; } } catch (InterruptedException e) { // do nothing } finally { finish(); Intent i = new Intent(); i.setClassName("com.testing.splashscreensample", "com.testing.splashscreensample.mainmenu"); startActivity(i); } } }; splashThread.start(); } }Run the app, and you’ll see your splash screen, followed by your main screen, and that’s that! We’ve obviously glossed over lots of fundamentals here, but I’ll be covering those in more detail in the weeks to come.

It Worked!!! After trying a dozen other approaches from other sites (that just didn’t work), I tried this one and ‘bingo! It worked – first time out the gate.
Big THANK YOU!!!
Awesome! Glad to have been of help
.
Thanks. I try oher sites, didn’t work, and this code works in the first. Thanks again!!!
thanks for nice guideline
I put in the same code and made sure the names that I changed are the same, but for some reason the program is crashing on my Droid. I have the Froyo 2.2 OS. The problem if with the main process. My best guess is when it tries to switch screen because it shows the title screen for the time allotted.
Awesome tutorial. Quick and easy. Just what I needed.
Is it possible to have like a video kind of splash screen?
You could probably combine animations with the splash screen technique. I’ll guy it a whirl a bit later an see what happens.
For some reason I’m not getting the .SplashScreen (Activity) in the box when I click on the Application tab. (423201092922PM.png) Do I add this manually and also add the Activity screen? Thanks for the great tutorial.
Nice Step by Step guidance,
One who started android newly
even they too can execute this
kind of things by using this tutorial
Thanks
Abdul Hameed Basha
Android Developer
AWESOME ! \m/
Gr8 same as everyone else this tutorial worked all other lack on noob basics.
Thank you
Wow, it actually worked the first time for the most part. I get a unexpected stop (force close) error after a couple of seconds. Any ideas?
What version of the SDK are you using? I was using 2.0 when I worked up that example, haven’t tried it under 2.2 yet.
2.2. I’ll try 2.0 and see if there is a difference on my end.
Hmmm. I don’t have an option for 2.0. I have 1.6, 2.1 and then 2.2.
I’ll have to update the sample to 2.2 and see what happens then. I’m pretty sure it’s not using the “best practices” approach; I’ve been meaning to update the sample to that method anyways, so this is a good excuse, heh.
One thing that I believe is important is that all goes to “boogers” after the while (waited<5000). The image comes up for whatever time value I place there and then the force close stuff come up. Not closing properly?
Thanks, barebonescoder! This is the closest i'm come to a successful splash example.
Got it to work perfectly! Now off to finding out how to include animated gifs! Thanks for this! I think the best splash tut for droid thus far!
What was the trick?
It is case sensitive!!!!
Make sure in this code that you define the variables as you used them before
i.setClassName(“com.testing.splashscreensample”, “com.testing.splashscreensample.mainmenu”);
VERY helpful!!! Thanks for taking the time to post =)
Really help ful, looking forward to see some animations in it
Even I was developing in 2.2 and i too was getting the ‘Force close’ error.
Then realized the case sensitive issue.
Now its workg fine. Excellent tutorial !! Thanks.
I tried ur tutorial.. but it keeps getting a force close error at the threading part.. Im not sure why.. Im using froyo 2.2
That worked perfectly – thank you so much for the step by step, I was getting errors in every new XML file because I’d just create a file, didn’t realize you had to select ANDROID XML. (le sigh)
Thanks again!
Just seemed to work perfectly first time on my Galaxy S with 2.1. Thank you.
Can the splash screen contains also some text as well as an image?
please send code for that……
thanking you
i want code related to flipping of activities.
how to flip the intent activities?
nice tut!
I LOVE YOU!!
if i was gay…
Simple, clear and straightforward. This tutorial was very helpful, thanks for taking the time to write it.
There is, however, one minor issue that I guess has been left for ‘students’ to work out for themselves for their homework
If the user presses the back or home buttons while the splashscreen is being displayed, the splashcreen disappears but the application is not terminated.
Good catch! If I ever get around to updating this post with latest version of Android I’ll try and address this.
Hello
really thanks of description ,I am student and use your description for my exercise but i got error like this
2011-04-02 23:48:31 – SplashScreen] New emulator found: emulator-5554
[2011-04-02 23:48:31 - SplashScreen] Waiting for HOME (‘android.process.acore’) to be launched…
[2011-04-02 23:49:13 - Emulator] emulator: emulator window was out of view and was recentred
[2011-04-02 23:49:13 - Emulator]
[2011-04-02 23:49:13 - SplashScreen] emulator-5554 disconnected! Cancelling ‘com.SplashScreen.SplashScreen activity launch’!
i dinot understand what is that and what i need .please quid me
cool, works also with android SDK 2.3.1. would be nice to have an alpha transition
Thanx for this nice tut.
Still don’t know how to implement a splash-schreen with preferences to disable or enable it the next time.
I already know how to do this with dialog-box but not with a real screen. Somebody ?
Thnx for the guideline.
It works
Thanks..,
It works..
But i am getting an issue..if i tried to press “back” or ”home” in splash screen it goes to home but within few seconds mainmenu screen appears !!! i want to close the app on back and home press…
any help..thanks
[...] http://www.barebonescoder.com/2010/04/a-simple-android-splash-screen/ This entry was posted in Uncategorized. Bookmark the permalink. ← Access the Address Book LikeBe the first to like this post. [...]
thx…
i have some problems. i want to load some datas when the splash is running. How to do?
Thank you very very much!
I needed it. Thanks a lot.
What Eclipse Theme are you using? It’s nice and hopefully publicly available… I’d like to use it as well.
Or just use Timer, 9 lines instead of 21:
Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
Intent intent = new Intent(SplashScreen.this, Main.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
}
}, 5000);
Thank you very much.. Worked first time Keep up the good work
life saver:::::))))
[...] we see that we have our image up for, you guessed it, five seconds. Crazy easy when compared to the Android sample I posted up last year. That’s it! Share and [...]
Superb! simple and effective tutorial
.
Nice tutorial.
Here I found another similar tutorial to display splash screen with Message and Handler classes.
http://www.mubasheralam.com/tutorials/android/how-create-splash-activity-android
I followed your tutorial and it worked on the first try. Now I can implement this into my conversion app. Thanks.
You rock !!!
Thank you
Thanks! I’m new to android Dev, and was looking for a tutorial like this.. and it worked in one try! I was impressed!
THANKS!!!
awesome post..it worked fine for me too..i was using android 2.2 with API version 8.thank you so much barebonescoder…
wow………this is realy good …………..and other example or other site not working but this one realy goood………….
Good. It worked like a charm. Except it throw an error during after the timer.
It was corrected after I referred to the case sensitive issue problem. Good.
Thank you so muck!!!!!!Mostly other sites were very tough.but urs is so simple and easy
thnxxx a lot
))