//wait 3 seconds
//start MainActivity
//finish splash
在protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);}
中定义一个线程,Thread timer = new Theard(){public void run(){
try{
sleep(3000); // time是一个长整型,以毫秒定义的 (wait 3 seconds)
}catch(InterruptedException e){ // 为防止不正常启动,增加catche.printStackTrace();
}finally{ // 等待三秒钟,如果没有出现异常,就在finally中启动MainActivity。
Intent openMainActivity = new Intent(); // startActivity()中需要Intent,所以在此定义一个Intent。(start MainActivity)startActivity(openMainActivity);
}}
};在AndroidManifest.xml的MAINACTIVITY activity中<inter-filter><action android:name="android.intent.action.MAINACTIVITY"/>改为<action android:name="com.gec_lab(picturename).appname.MAINACTIVITY"/>。
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timer = new Theard(){
public void run(){
try{
sleep(3000);
}catch(InterruptedException e){
e.printStackTrace(); // 将异常简单输出
}finally{
Intent openMainActivity = new Intent();
startActivity(openMainActivity); // 启动MainActivity
}
}
};
timer.start(); // 启动线程
}
protected void onPause(){ // 重写onPause,单击右键,Source->Override/Implement Methods->onPause()
super.onPause();
finish(); // finish splash
}