Tuesday, May 31, 2011

splash screen

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

public class SplashActivity extends Activity
{
    private static long SPLASHTIME = 2500;
    private static final int STOPSPLASH = 0;
    public static Activity mainApp;
    public static boolean shouldNavigate = true;

    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setRequestedOrientation(1);
        mainApp = this;
        setContentView(R.layout.main);
        final Message msg = new Message();
        msg.what = STOPSPLASH;
        mHandler.sendMessageDelayed(msg, SPLASHTIME);

    }

    Handler mHandler = new Handler()
    {

        public void handleMessage(Message msg)
        {
            switch (msg.what)
            {
            case STOPSPLASH:

                if (shouldNavigate)
                {
                    Intent myIntent = new Intent();
                    /*myIntent.setClassName("mon.ctacts",
                            "mon.ctacts.LoginActivity");*/
                    myIntent.setClassName("com.traveldairy",
                    "com.traveldairy.AfterSplashActivity");
                   
                    startActivity(myIntent);
                    finish();
                }
                break;

            }

            super.handleMessage(msg);
        }
    };

    public void finishFromChild(Activity child)
    {
        // TODO Auto-generated method stub
        finish();
        super.finishFromChild(child);
    }
}

Xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/root"
    android:background="@drawable/stockquitybackground">

</LinearLayout>

No comments:

Post a Comment