I'm making a feature that redirects the user to another activity once the timer reaches zero. I tried to swap the places of these if-else statements but the app keeps crashing. What could be the problem?
This is my countdown time block:
private void startTimer(TextView timerTextView) {
examTimer = new Timer();
examTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if(seconds == 0){
minsTotalTime--;
seconds = 59;
}
else if (seconds == 0 && minsTotalTime == 0){
examTimer.purge();
examTimer.cancel();
Toast.makeText(ExamActivity.this, "Time ran out", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(ExamActivity.this, ExamResults.class);
intent.putExtra("correct", getCorrectAnswers());
intent.putExtra("incorrect", getIncorrectAnswers());
startActivity(intent);
finish();
}
else {
seconds--;
}
}