2011-06-27 9 views
4

私はアンドロイドアプリケーションを作成しています。私はlogo screen(Activity)、次に私はhome screen(another activity)です。私は自分のアプリケーションを起動するときに私のロゴ画面が来て、自動的に2秒後に私のホーム画面が表示されるはずです。誰でも私に何をすべきか教えてもらえますか?アンドロイドでの新しいアクティビティの自動開始

答えて

8

これを使用してください。..

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.os.Handler; 

public class Logo extends Activity { 
protected boolean _active = true; 
protected int _splashTime = 2000; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.logo); 

    Handler handler = new Handler(); 
    handler.postDelayed(new Runnable() { 
     public void run() { 
      finish(); 
      Intent i3 = new Intent(Logo.this, Home.class); 
       startActivity(i3); 
     } 
    }, _splashTime); 
} 
} 
+0

また、ユーザがスプラッシュ画面でアプリを閉じる(戻るボタンを押す)と、バックグラウンドで実行されているハンドラのために次のアクティビティがまだ開いている場合は、今後の読者のために、onBackPressed 。 – Antrromet

1

あなたはTimerTask.On TimerTaskをを使用することができます2の後にタスクをスケジュールminutes.Andリンク TimerTask

を参照タイマータスクを使用するには

下のタスクを実行します

LogoScreen.this.startActivity(新しいインテント(LogoScreen.this、HomeScreen.class));

関連する問題