android 歡迎介面

oufu發表於2015-08-26
  1. public class WelcomeActivity extends Activity{  
  2.       
  3.     private final long SPLASH_LENGTH = 2000;    
  4.         Handler handler = new Handler();  
  5.     public void onCreate(Bundle savedInstanceState) {  
  6.         super.onCreate(savedInstanceState);  
  7.         setContentView(R.layout.welcome);  
  8.         handler.postDelayed(new Runnable() {  //使用handler的postDelayed實現延時跳轉  
  9.               
  10.             public void run() {    
  11.                 Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);    
  12.                 startActivity(intent);    
  13.                 finish();       
  14.             }    
  15.         }, SPLASH_LENGTH);//2秒後跳轉至應用主介面MainActivity  
  16.           
  17.     }  

  1. }  

  1.  /** 
  2.      * 延遲多少秒進入主介面 
  3.      * @param min 秒 
  4.      */  
  5.     private void skipActivity(int min) {  
  6.         new Handler().postDelayed(new Runnable() {  
  7.   
  8.             @Override  
  9.             public void run() {  
  10.                 Intent intent = new Intent(WelComeActivity.this,  
  11.                         TabHostMain.class);  
  12.                 startActivity(intent);  
  13.                 WelComeActivity.this.finish();  
  14.             }  
  15.         }, 1000*min);  
  16.     }  

相關文章