2011-06-24 107 views
2

我不知道,什麼是阻止這個工作。我有代碼設置導致3秒延遲,但視圖不工作,它保持黑色,然後3秒後切換到下一個屏幕。我想,我做的時間延遲,一些沒有被調用內Android的顯示佈局...Android之間的時間延遲

public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState);  
    start = System.currentTimeMillis(); 
    setContentView(R.layout.team); 
} 

protected void onStart() 
{ 
    super.onStart();   
    while(game) 
    { 
     now = System.currentTimeMillis(); 
     if (now - start >= 5000) 
     { 
      game = false; 
      Intent about = new Intent(this, SplashScreen.class); 
      startActivity(about); 
     } 
    } 
} 

回答

4

我相信你想實現一個屏幕,延遲幾秒鐘,然後啓動你的主應用程序。就像啓動畫面在主應用程序啓動之前一樣?

然後這會幫助你!

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    /** set time to splash out */ 
    final int welcomeScreenDisplay = 4000; 
    /** create a thread to show splash up to splash time */ 
    Thread welcomeThread = new Thread() { 

    int wait = 0; 

    @Override 
    public void run() { 
    try { 
    super.run(); 
    /** 
    * use while to get the splash time. Use sleep() to increase 
    * the wait variable for every 100L. 
    */ 
    while (wait < welcomeScreenDisplay) { 
    sleep(100); 
    wait += 100; 
    } 
    } catch (Exception e) { 
    System.out.println("EXc=" + e); 
    } finally { 
    /** 
    * Called after splash times up. Do some action after splash 
    * times up. Here we moved to another main activity class 
    */ 
    startActivity(new Intent(CurrentActivity.this, NextActivity.class)); 
    finish(); 
    } 
    } 
    }; 
    welcomeThread.start(); 
} 

這是一個4秒延遲的屏幕。

+1

完美沒有意識到這必須在一個線程內完成 – Chris

+1

我很高興我幫助:) – Shah

0

您應該使用Timer類推出新的活動。