Reference http://www.cnblogs.com/royenhome/archive/2010/05/05/1727971.html
Mainmenu. Java
Package Com. Demo;
Import Android. App. activity;
Import Android. OS. Bundle;
Public Class Mainmenu Extends Activity {
@ Override
Protected VoidOncreate (bundle savedinstancestate ){
Super. Oncreate (savedinstancestate );
This. Setcontentview (R. layout. Main );
}
}
Test. Java
Code Package Com. Demo;
ImportAndroid. App. activity;
ImportAndroid. content. intent;
ImportAndroid. OS. Bundle;
ImportAndroid. util. log;
ImportAndroid. View. keyevent;
Public class test extends activity {
private long m_dwsplashtime = 3000 ;< br> private Boolean m_bpaused = false ;
private Boolean m_bsplashactive = true ;
/**Called when the activity is first created.*/
@ Override
Public VoidOncreate (bundle savedinstancestate ){
Super. Oncreate (savedinstancestate );
Setcontentview (R. layout. Splash );
Thread splashtimer = New Thread ()
{
Public Void Run (){
Try {
// Wait Loop
Long MS = 0 ;
While (M_bsplashactive && MS < M_dwsplashtime ){
Sleep ( 100 );
If(!M_bpaused)
MS+ =100;
}
Startactivity ( New Intent ( " Com. Google. App. Splashy. clearsplash " ));
}
Catch (Exception ex ){
Log. E ( " Splash " , Ex. getmessage ());
}
Finally {
Finish ();
}
}
};
Splashtimer. Start ();
}
@ override
protected void onpause () {
super . onpause ();
m_bpaused = true ;< BR >}
@ Override
Protected VoidOnresume (){
Super. Onresume ();
M_bpaused=False;
}
@ Override
Public Boolean Onkeydown ( Int Keycode, keyevent event ){
Super . Onkeydown (keycode, event );
Switch (Keycode ){
Case Keyevent. keycode_menu:
M_bsplashactive = False ;
Break ;
Case Keyevent. keycode_back:
/* Two exit Methods */
/* System. Exit (0 ); */
/* Android. OS. process. killprocess (Android. OS. process. mypid ()); */
Android. OS. process. killprocess (Android. OS. process. mypid ());
Break ;
Default :
Break ;
}
Return True ;
}
}
Androidmanifest. xml configuration is very important.
Code
<? XML version = "1.0" encoding = "UTF-8" ?>
< Manifest Xmlns: Android = "Http://schemas.android.com/apk/res/android"
Package = "Com. Demo"
Android: versioncode = "1"
Android: versionname = "1.0" >
< Application Android: icon = "@ Drawable/icon" Android: Label = "@ String/app_name" >
< Activity Android: Name = "Test" 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 = ". Mainmenu" Android: Label = "@ String/app_name" >
< Intent-Filter >
< Action Android: Name = "Com. Google. App. Splashy. clearsplash" />
< Category Android: Name = "Android. Intent. Category. Default" />
</ Intent-Filter >
</ Activity >
</ Application >
</ Manifest >