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'를 사용하여 어떤 행동을 프로그램하십시오. –