Showing posts with label Android Splash screen demo. Show all posts
Showing posts with label Android Splash screen demo. Show all posts

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 :)

 

Copyright @ 2013 Android Developers Blog.