Monday, 27 August 2012

Android Splash Screen Example

Android Splash Screen Example
Hello Friends,

Have you searching for Splash screen demo example in android ??
Today , I am sharing the full running code of splash screen in android.

1. SplashScreen.java

package com.mukesh.tutorials.splash;

import com.pxr.tutorials.splash.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;

public class SplashScreen extends Activity {
        
        protected int _splashTime = 5000; 
        
        private Thread splashTread;
        
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash);
            
            
            final SplashScreen sPlashScreen = this; 
            
            // thread for displaying the SplashScreen
            splashTread = new Thread() {
                @Override
                public void run() {
                    try {                       
                        synchronized(this){
                                wait(_splashTime);
                        }
                        
                    } catch(InterruptedException e) {} 
                    finally {
                        finish();
                        
                        Intent i = new Intent();
                        i.setClass(sPlashScreen, Main.class);
                                startActivity(i);
                        
                        //stop();
                    }
                }
            };
            
            splashTread.start();
        }
        //for fading effect
        /*@Override
        public boolean onTouchEvent(MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                synchronized(splashTread){
                        splashTread.notifyAll();
                }
            }
            return true;
        }*/
        
}


2.AndroidManifest.xml

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

      package="com.pxr.tutorials.splash"

      android:versionCode="1"

      android:versionName="1.0">

    <uses-sdk android:minSdkVersion="4" />



    <application android:icon="@drawable/icon" android:label="@string/app_name">

        <activity android:name=".SplashScreen"

                  android:label="@string/app_name">

            <intent-filter>

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

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

            </intent-filter>

        </activity>

       

        <activity android:name="com.mukesh.tutorials.splash.Main" />

    </application>

</manifest>


3.Main.Java


package com.mukesh.tutorials.splash;

import com.pxr.tutorials.splash.R;

import android.app.Activity;
import android.os.Bundle;

public class Main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}




Download Source Code: 
SplashDemo


Hope this will helps anyone....
Enjoy :)

Mukesh Yadav

Hi Guys I am from Delhi working as Web/Mobile Application Developer(Android Developer), also have knowledge of Roboelctric and Mockito ,android test driven development... Blogging has been my passion and I think blogging is one of the powerful medium to share knowledge and ideas....

5 comments:

  1. Some screenshots of you app would have made your post much more intresting.. :) anyways, thanks...

    ReplyDelete
  2. where is your xml file i mean images that display in splash screen ??

    ReplyDelete
  3. please help to create animated splash screen on android

    ReplyDelete
  4. please help to create animated splash screen on android

    ReplyDelete
    Replies
    1. Hello Aswathy,
      Check this tutorial for animated splash screen, hope
      this will help you.
      http://www.androiddevelopersolutions.com/2014/07/android-splash-screen-example-with.html

      Delete

 

Copyright @ 2013 Android Developer Blog.

Blog Widget by LinkWithin