public class Splashscreen extends Activity
{
private static final int SPLASH_TIME = 10 * 1000;// 3 seconds
Button logo;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splashscreen);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
try {
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent = new Intent(Splashscreen.this,MainActivity.class);
startActivity(intent);
Splashscreen.this.finish();
//overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
}, SPLASH_TIME);
new Handler().postDelayed(new Runnable() {
public void run() {
}
}, SPLASH_TIME);
} catch(Exception e){}
// METHOD 1
/****** Create Thread that will sleep for 5 seconds *************/
Thread background = new Thread() {
public void run() {
try {
// Thread will sleep for 5 seconds
sleep(50*1000);
// After 5 seconds redirect to another intent
Intent i=new Intent(getBaseContext(),MainActivity.class);
startActivity(i);
//Remove activity
finish();
} catch (Exception e) {
}
}
};
background.start();
}
只是使用標誌沒有歷史的警告 - 該SYSTEN會隨時結束活動的任何其他活動啓動後。這很難控制應用程序代碼。所以不要在no_history活動的破壞函數中釋放任何東西。這會導致意外和難以調試的異常 – png 2012-01-09 08:05:38