0

わかりました、1.5 秒間一時停止し、1 つのことを除いてうまく機能するスプラッシュ スクリーンに取り組んでいます。構成 (方向) が変更された場合に が開始されると、がtimerリセットされ、最終的に2 回開始されます。 onCreatetimerParchmentActivity.java

ハンドラーがインテントを 2 回送信しないようにするにはどうすればよいですか?

前もって感謝します!

完全なコードは @: https://github.com/n00bware/android_apps_parchmentにあります。

これが私のコードです(例http://www.anddev.org/novice-tutorials-f8/splash-fade-activity-animations-overridependingtransition-t9464.htmlから):

public class SplashScreen extends Activity {

private static final int SPLASH_DISPLAY_TIME = 1500;  /* 1.5 seconds */
private static final String TAG = "Parchment";

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

   /* Create a new handler with which to start the main activity
      and close this splash activity after SPLASH_DISPLAY_TIME has
      elapsed. */
   new Handler().postDelayed(new Runnable() {
       @Override
       public void run() {

           Intent parchment = new Intent(SplashScreen.this, ParchmentActivity.class);
           SplashScreen.this.startActivity(parchment);
           SplashScreen.this.finish();
           overridePendingTransition(R.anim.fade_main_in, R.anim.fade_splash_out);
        }
    }, SPLASH_DISPLAY_TIME);
}

/* I found a suggestion to try overriding onConfigurationChanged()
   but it doesn't stop a new timer from being started */

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

/* I also tried overriding onStart() but this also doesn't stop a
   new timer. What exactly is called when an orientation configuration
   changes happens? */
@Override
public void onStart() {
    super.onStart();
    setContentView(R.layout.splash);
}
4

2 に答える 2

1

新しい静的ブール値を作成してfalseに設定し、作成時にフラグがfalseの場合にのみハンドラーアクションを実行できます...

PS:ifステートメント内で、ブールフラグをtrueに設定する必要があります:)

幸運を!

于 2011-11-30T22:01:57.840 に答える
1

onCreate でハンドラーを作成し、onDestroy でそれを解放し、onStart でメッセージを送信/runnable を投稿し、onStop でメッセージ/runnable を削除します。

これにより、回転するたびにタイマーがリセットされるため、デバイスを毎秒回転させた場合、スプラッシュ画面を表示したままにすることができます。

Android では、回転を切り替えるのに 1 秒ほどかかる場合があります。アプリを起動して回転してもスプラッシュが表示されない可能性があるため、おそらくこの動作が必要です。

于 2011-11-30T22:31:22.730 に答える