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