2

基本的にしばらくスリープし、別のアクティビティを初期化するアクティビティがあります。この睡眠時間中に、私は画面上にいくつかのアニメーションを描きます。

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    View splashScreen = new SplashScreenView(this);
    setContentView(splashScreen);
    Thread splashThread = new Thread(){
        public void run(){
            try{
                sleep(6500);
                startActivity(new Intent("com.example.LOGIN"));
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            finally{
                finish();
            }
        }
    };
    splashThread.start();
}

しかし、画面の向きが変わると、アクティビティが再開されました。そのため、マニフェスト ファイルを変更することで対応しました。

<activity
        android:name=".SplashScreenActivity"
        android:configChanges="orientation|keyboardHidden"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

1つ問題が残っています。アクティビティが再起動しないようにしていますが、SplashScreenView クラスの onDraw() 関数は引き続き再起動します。

protected void onDraw(Canvas canvas) {

    canvas.drawBitmap(dstbmp2, logoX, logoY, null);
    canvas.drawBitmap(dstbmp, ballX, ballY, null);

    // Update the position of the ball.

    update();

    // Delay
    try {  
        Thread.sleep(100);  
    } catch (InterruptedException e) { }

    invalidate();

}
4

1 に答える 1

1

アクティビティでこのメソッドをオーバーライドします。

public void onConfigurationChanged(Configuration newConfig) {

    }        

グローバルブール変数を宣言し、このメソッドでたとえば true に設定します。次に、onCreate() で、本当に新しいインスタンスを作成しsplashScreenて開始するかどうかを決定できますsplashThread

于 2012-07-04T08:56:30.520 に答える