0
私は、ユーザが質問に答える時間を与えられた後、結果を示すためにインテントが呼び出されるゲームモジュールを作った。私の問題は、途中でアクティビティを終了するときである。私がどんな活動をしているかにかかわらず、ゲームで完了した時間の結果はまだ表示されます。CountdownTimerとアクティビティを終了する
タイマーのための私のコードは
class MyCount extends CountDownTimer{
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
Intent finish= new Intent(QuestionScreen.this,ResultScreen.class);
finish.putExtra("noofques", Integer.toString(totalquestions));
finish.putExtra("correct", Integer.toString(score));
startActivity(finish);
overridePendingTransition(R.anim.slideinleft, R.anim.slideoutleft);
}
@Override
public void onTick(long millisUntilFinished) {
if(millisUntilFinished>60000)
timerview.setText((millisUntilFinished/(1000*60))+1 +" minutes left");
else
{
timerview.setText(millisUntilFinished/1000 +" seconds left");
}
}
}
と途中でゲームを終了するためのコードである
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
alertbox.setMessage("Do you really want to quit");
alertbox.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Intent info = new Intent(QuestionScreen.this,com.preciselabs.mental_skills.MenuScreen.class);
info.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(info);
overridePendingTransition(R.anim.slideinright, R.anim.slideoutright);
}
});
alertbox.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
}
});
alertbox.show();
return true;
}
return super.onKeyDown(keyCode, event);
}
大幅
'onTick'を使用せず、何らかのアクションをプログラムするために' java.util.Timer'を使用してください。 –