I have an AlertDialog with a countdown timer in it, and I have a cancel button, and it cancels the dialog, but the timer continues to move! Does anyone know how to cancel the countdown of the countdown timer? Any help would be appreciated!
private void timerDialog() { timerDialog = new AlertDialog.Builder(this).create(); timerDialog.setTitle("Timer"); timerDialog.setMessage("Seconds Remaining: "+timerNum*1000); timerDialog.setCancelable(false); timerDialog.setButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface aboutDialog, int id) { timerDialog.cancel(); } }); timerDialog.show(); new CountDownTimer(timerNum*1000, 1000) { @Override public void onTick(long millisUntilFinished) { timerDialog.setMessage("Seconds Remaining: "+ (millisUntilFinished/1000)); } @Override public void onFinish() { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(500); timerDialog.cancel(); } }.start(); }
source share