2011-06-24 9 views
2

私はよく分かりません。 3秒の遅延が発生するようにコードを設定していますが、表示が機能していないと、黒で表示され、3秒後に次の画面に切り替わります。私は、あなたが新しいアクティビティを起動するTimerクラスを使用する必要がありますビュー間のアンドロイドの時間遅れ

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

...私は時間遅延をやっていると、何かがレイアウトを表示するには、Android内で呼び出されていない、と思います。