Click here to Skip to main content
13,449,659 members (49,629 online)
Click here to Skip to main content
Add your own
alternative version


118 bookmarked
Posted 29 Sep 2010

An Advanced Splash Screen for Android App

, 29 Sep 2010
Rate this:
Please Sign up or sign in to vote.
The splash screen Android tutorial


Everyone wants his/her application to be beautiful and attractive for an eye of a user. And there are a lot of applications, at least desktop applications, mostly games that use splash screens. It’s nice and, moreover, while the splash screen is working, you can initialize your application. Many tutorials exist explaining how to begin Android programming and I won't repeat them here. You can find them all over the internet. So I will show only the programming stuff.

The Beginning

Create a new Android Eclipse project with the following settings:

Project name : AdvancedSplashDemo
Build target: I've set it to Android 2.1
Application name: Advanced Splash Demo
Package name: Advanced Splash Demo
Create Activity: MainActivity – it will be the application itself 

So, as we don’t need a splash screen after it’s done, the first thought is to use another activity that will start the main activity and silently die after that. Let’s create a layout for the splash – it will be a linear layout and an Image View inside it. Create a new Android XML file "splash.xml" in appfolder/res/layout folder. Don’t make it fill parent, as we want it to be really as splash screen. The image view has to wrap a content too:

<?xml version="1.0" encoding="utf-8"?>













Here the gravity attribute value is set to "center" to make the splash to be at the center of the screen. Add some picture to the appfolder/res/drawable folder and press F5 on the project. I’ve added lnxins.png and as you can see, set it as the image view source.

So far, let’s look at the application manifest. It has now just one “.MainActivity” activity set as a launcher. We’ll set it as default category and add another splash activity with a splash layout and will set it as the launcher. Open the manifest and open an application tab. For the main activity, change an Android intent category to default. Near application nodes press an “Add…” button, choose create a new element at top level and double click on Activity. For new activity, click on a “Name*” hyperlink and enter “SplashScreen” class. In sources, a new class will be added for the splash activity. Next, press the “Add…” button again for the SplashScreen node and add the intent filter. Again, for just added intent filter, add an action and a category.

Set the action to android.intent.action.MAIN and the category to android.intent.category.LAUNCHER. So the Splash screen activity will be run first. The manifest should look like the following:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""



    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MainActivity"

                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT"/>
        <activity android:name="SplashScreen">
                <action android:name="android.intent.action.MAIN"></action>
                <category android:name="android.intent.category.LAUNCHER"></category>

A Little Coding

Open class. Now it has overridden onCreate method only. Override onTouchEvent method to give the user a possibility to close splash screen at every moment. And don’t forget synchronization or you will have random crashes. Here’s the class code:

 public class SplashScreen extends Activity {
     * The thread to process splash screen events
    private Thread mSplashThread;    

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

        // Splash screen view
        final SplashScreen sPlashScreen = this;   
        // The thread to wait for splash screen events
        mSplashThread =  new Thread(){
            public void run(){
                try {
                        // Wait given period of time or exit on touch
                catch(InterruptedException ex){                    

                // Run next activity
                Intent intent = new Intent();
                intent.setClass(sPlashScreen, MainActivity.class);
     * Processes splash screen touch events
    public boolean onTouchEvent(MotionEvent evt)
        if(evt.getAction() == MotionEvent.ACTION_DOWN)
        return true;

It’s time now to make a first run. And we have the splash screen waiting for 5 seconds. Doesn’t look good, just two black screens, one after another.

A Little Beautification

First, let’s make the splash screen transparent. In appfolder/res/values, add new Android XML file styles.xml and add to it a transparent theme:

    <style name="Theme.Transparent" parent="android:Theme">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:backgroundDimEnabled">false</item>

Here are some explanations: as you can see, the style’s parent is android:Theme so we could apply it to our activity. And as you can see, the attribute's names are clear and you can understand what they mean.

Next, we’ll apply this theme to our splash. In the manifest file for the splash activity, set a "theme" attribute to the just created theme:




        <action android:name="android.intent.action.MAIN"></action>
        <category android:name="android.intent.category.LAUNCHER"></category>

Let’s suppose we’re developing a game application. And gamers don’t like when something distracts them from the game process. Most of them prefer fullscreen mode. So, set the fullscreen theme for the main activity:

<activity android:name=".MainActivity"



        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.DEFAULT"/>

Run it. Looks better. Now we’ll make it fade-in and fade-out. Create in appfolder/res folder new folder "anim" and add to it two Android XML files – appear.xml and disappear.xml. They will be alpha animations.


<set xmlns:android="">


        android:fromAlpha="0.0" android:toAlpha="1.0"




<set xmlns:android="">


        android:fromAlpha="1.0" android:toAlpha="0.0"



In these animations, they just change the alpha channel of an object from fromAlpha value to toAlpha value for a given period of time. Now add new style in styles.xml:

<style name="Animations" parent="@android:Animation" />
    <style name="Animations.SplashScreen">
        <item name="android:windowEnterAnimation">@anim/appear</item>
        <item name="android:windowExitAnimation">@anim/disappear</item> 

So, on the window, enter the “appear” animation will be performed and on the window exit the “disappear” animation will be performed. Add this style to Theme.Transparent theme:

<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowAnimationStyle">@style/Animations.SplashScreen</item></style>  

Ok, it’s time to run it again. Now it looks nice. And more…

Don’t Shoot at a Programmer, He Draws As He Can…

Let’s create an animated splash screen. As an artist, I’m not very good so I used Gimp’s Script-Fu to generate a set of frames for animations. First, remove android:src attribute in splash.xml. Then, in the drawable folder, create flag.xml:

 <?xml version="1.0" encoding="utf-8"?>




    <item android:drawable="@drawable/f03" android:duration="100" />
    <item android:drawable="@drawable/f04" android:duration="100" />
    <item android:drawable="@drawable/f05" android:duration="100" />
    <item android:drawable="@drawable/f06" android:duration="100" />
    <item android:drawable="@drawable/f07" android:duration="100" />
    <item android:drawable="@drawable/f08" android:duration="100" />
    <item android:drawable="@drawable/f09" android:duration="100" />
    <item android:drawable="@drawable/f10" android:duration="100" />    

Here is a set of frames and “oneshot” attribute says to loop them. To run animation, we need to change the splash screen class code. To the onCreate method, add the following:

final ImageView splashImageView = (ImageView) findViewById(;
final AnimationDrawable frameAnimation =

We've set the animation for the splash, but here’s a little problem. We can’t start it from the onCreate method. The animation must be started from GUI thread. For this, we’ll use a “post” method of the ImageView class. It will add our runnable to a message queue and when GUI thread will be available, it will start it: Runnable(){
            public void run() {

And here we are:


That’s all. Have fun with Android programming.



  • 29th September, 2010: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Igor Kushnarev
Software Developer
Russian Federation Russian Federation
• More than 10 years experience in software development
• 3 years experience in direction of automation department.
• software engineering: experience in the whole life cycle of software development
• languages: C#, VB.Net, ASP.NET, HTML, XML, JavaScript, Visual FoxPro, MS SQL, C++, Java, T-SQL, Objective-C
• Gathering, specification and the analysis of requirements of the customer to the software.
• The analysis of a subject area.
• Estimations of labour input of development.
And so on...

You may also be interested in...


Comments and Discussions

SuggestionFundamental Error. Operation on back button Pin
VariantFuture17-Jul-11 8:43
memberVariantFuture17-Jul-11 8:43 
GeneralRe: Fundamental Error. Operation on back button Pin
Igor Kushnarev17-Jul-11 17:55
memberIgor Kushnarev17-Jul-11 17:55 
GeneralRe: Fundamental Error. Operation on back button [modified] Pin
VariantFuture18-Jul-11 5:05
memberVariantFuture18-Jul-11 5:05 
GeneralRe: Fundamental Error. Operation on back button Pin
Igor Kushnarev18-Jul-11 8:02
memberIgor Kushnarev18-Jul-11 8:02 
Questionthanks Pin
GoldCoinSoftware9-Jul-11 18:13
memberGoldCoinSoftware9-Jul-11 18:13 
GeneralMy vote of 5 Pin
GoldCoinSoftware9-Jul-11 18:13
memberGoldCoinSoftware9-Jul-11 18:13 
QuestionHOW DO YOU Pin
Member 767280014-Feb-11 15:33
memberMember 767280014-Feb-11 15:33 
AnswerRe: HOW DO YOU Pin
Igor Kushnarev14-Feb-11 19:08
memberIgor Kushnarev14-Feb-11 19:08 
The main activity is not running in the background. You can set breakpoints at startActivity call in SplashScreen class and in onCreate method in MainActivity class and you will see that the splash screen is started and MainActivity is not.

If you read docs you can see following:

Activity Action: Start as a main entry point, does not expect to receive data.

We have to entry points at this moment - SplashScreen and MainActivity.

But also there is docs for

The activity can be the initial activity of a task and is listed in the top-level application launcher.

So, Android makes it a main entry point and MainActivity is not started, it's not in a backround.

Really ACTION_MAIN for MainActivity can be deleted from the manifest. It's unnecessary
GeneralRe: HOW DO YOU Pin
Member 767280014-Feb-11 23:20
memberMember 767280014-Feb-11 23:20 
GeneralRe: HOW DO YOU Pin
Igor Kushnarev15-Feb-11 1:27
memberIgor Kushnarev15-Feb-11 1:27 
QuestionRe: HOW DO YOU Pin
Member 767280015-Feb-11 2:01
memberMember 767280015-Feb-11 2:01 
AnswerRe: HOW DO YOU Pin
Igor Kushnarev15-Feb-11 2:39
memberIgor Kushnarev15-Feb-11 2:39 
GeneralRe: HOW DO YOU Pin
Member 767280015-Feb-11 8:35
memberMember 767280015-Feb-11 8:35 
GeneralRe: HOW DO YOU Pin
Igor Kushnarev15-Feb-11 19:37
memberIgor Kushnarev15-Feb-11 19:37 
GeneralRe: HOW DO YOU Pin
Roman Reibnagel15-Mar-11 22:18
memberRoman Reibnagel15-Mar-11 22:18 
GeneralRe: HOW DO YOU [modified] Pin
Igor Kushnarev16-Mar-11 19:03
memberIgor Kushnarev16-Mar-11 19:03 
GeneralRe: HOW DO YOU Pin
dansoft9-Sep-11 4:47
memberdansoft9-Sep-11 4:47 
GeneralRe: HOW DO YOU Pin
Igor Kushnarev9-Sep-11 7:03
memberIgor Kushnarev9-Sep-11 7:03 
GeneralRe: HOW DO YOU Pin
dansoft9-Sep-11 21:00
memberdansoft9-Sep-11 21:00 
GeneralRe: HOW DO YOU Pin
Igor Kushnarev9-Sep-11 21:45
memberIgor Kushnarev9-Sep-11 21:45 
GeneralRe: HOW DO YOU Pin
dansoft10-Sep-11 3:30
memberdansoft10-Sep-11 3:30 
GeneralRe: HOW DO YOU Pin
Igor Kushnarev10-Sep-11 6:06
memberIgor Kushnarev10-Sep-11 6:06 
Generalhow to make Your Animated Splash Screen As my "WebView PreLoader" Pin
Member 1007165728-May-13 7:46
memberMember 1007165728-May-13 7:46 
GeneralGreat article Pin
Freddie Wang26-Nov-10 3:25
memberFreddie Wang26-Nov-10 3:25 
GeneralRe: Great article Pin
Igor Kushnarev28-Nov-10 19:22
memberIgor Kushnarev28-Nov-10 19:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180318.3 | Last Updated 29 Sep 2010
Article Copyright 2010 by Igor Kushnarev
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid