Thursday 19 January 2012

create Splash screen

create following two files in you project and in Manifest.xml make splasscreen as main activity

<activity android:name=".splashscreen">
   
    <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
    </activity> 

splash.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:background="@drawable/spl">
</RelativeLayout>

splashscreen.java


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;

public class splashscreen extends Activity{

    protected boolean _active = true;
    protected int _splashTime = 3000;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE); // No title displays
        setContentView(R.layout.splash);

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
                finish();
               
                Intent i=new Intent(splashscreen.this,MainScreen.class);
                startActivity(i);
               
                            }
        }, _splashTime);
    }
   
}

No comments: