0

カウントダウンタイマーを実行し、タイマーが切れるとアラートボックスを表示してゲームを再開できるアプリがあります。残念ながら、戻るボタンを押してアプリを再度開くと、元のカウントダウンタイマーが切れるはずだった頃にクラッシュします。

次のコードは、私のアクティビティの onCreate にあります。

        CountDownTimer cdt = new CountDownTimer(totalTime*1000, 1000) { 
        public void onTick(long millisUntilFinished) {
            time = (int) ((millisUntilFinished)/1000)*100/totalTime;             
            TimeBar.setProgress(time);
        }

        public void onFinish() {
            time = 0;            
            TimeBar.setProgress(time);
            AlertDialog.Builder alertbox = new AlertDialog.Builder(mContext);
            alertbox.setMessage("Sweet! " + score + " points!");
            alertbox.setPositiveButton("Leaderboard", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    ScoreloopManagerSingleton.get().onGamePlayEnded((double) score, null);
                    startActivity(new Intent(BubblesActivity.this, LeaderboardsScreenActivity.class));
                    BubblesActivity.this.finish();

                }
            });
            alertbox.setNeutralButton("Replay", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    BubblesActivity.this.finish();
                    startActivity(new Intent(BubblesActivity.this, BubblesActivity.class));

                }
            });
            if(alertbox!= null)
                alertbox.show();



        }
    }.start();
4

1 に答える 1

0

スタック トレースがなければ、何が起こるかはわかりませんがActivityCountDownTimer.

enter code hereCountDownTimer.cancel() を呼び出すと、onDestroy()おそらくこれが解決します。

于 2012-02-12T17:53:56.690 に答える