2011-04-30 53 views

回答

4
public class SplashScreen extends Activity { 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splashscreen); 
    Thread splashThread = new Thread() { 
    @Override 
    public void run() { 
     try { 
      int waited = 0; 
      while (waited < 1000) { 
       sleep(100); 
       waited += 100; 
      } 
     } catch (InterruptedException e) { 
      // do nothing 
     } finally { 

      Intent i = new Intent(SplashScreen.this,Party_tablayout.class); 

      startActivity(i); 
      finish(); 
     } 
    } 
    }; 
    splashThread.start(); 
} 
} 

希望這有助於你.. :-)

0

創建一個啓動器活動,在那裏你只顯示你的bg圖像,也許一個進度條或其他東西。 做一切需要時間的地方。就像預加載一堆位圖一樣,從互聯網上獲取東西,不管你的應用需要加載多久。 完成後,通過意向調用您的主要活動。

1

謝謝老兄,它確實有效。但你也可以在try塊中使用不同的代碼。 是這樣的:

Thread th = new Thread(){ 
    public void run(){ 
    try { 
     long current = System.currentTimeMillis(); 
     while(System.currentTimeMillis() <= current + 6000){ 
     //do nothing. 
     } 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } finally { 
     final Intent intent = new Intent(NeredeyimBenActivity.this, AnaSayfa.class); 
     startActivity(intent); 
    } 
    } 
}; 
th.start();