私はあなたに割り当てられた分後に割り当てられた数分以内にすることができますように多くの質問..アクティビティはfinish()の後もまだ続きます。
に答える必要があります全体gameactivityのタイマーを持ってクイズアプリを持っているが終わって、それは結果のアクティビティが表示されますあなたのスコアを示す。バックプレスでは、メインメニューに戻るかどうか尋ねる警告ダイアログを作成しました。 「はい」をクリックすると、ページはメインメニューに戻り、ゲームの活動を停止/終了します。
しかし、「はい」をクリックすると、メインメニューに戻りますが、アプリケーション内のどこにいても前回のゲームアクティビティからの結果は表示されます。すぐにあなたの現在の活動を終了します)(終了し保証はありません
new CountDownTimer(seconds, 1000) {
public void onTick(long millisUntilFinished) {
timer.setText("Seconds left: " + millisUntilFinished/1000);
}
public void onFinish() {
Intent intent = new Intent(GameActivityAddition.this, Score.class);
intent.putExtra("totalscore", score);
intent.putExtra("numberquestions", rowId);
intent.putExtra("d", difficulty);
db.close();
startActivity(intent);
}
}.start();
@Override
public void onBackPressed() {
AlertDialog.Builder abuilder = new Builder(GameActivityAddition.this);
abuilder.setMessage("Return to Main Menu?");
abuilder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent main = new Intent(GameActivityAddition.this, Main.class);
startActivity(main);
finish();
}
});
abuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = abuilder.create();
alert.show();
}
結果アクティビティに設定したデータである可能性もあります。アクティビティを終了するとクリアされないため、再度アクティビティにアクセスしたときに古いデータが表示されることがあります。 – Hiral
カウントダウンを停止していません。 – user996428
私が推測するように、カウントダウンタイマーはスレッドのように機能し、finish()を呼び出しても実行を続けます。ブーリアン変数をタイマーに追加して、実行を制御してください。 – Huang