I am trying to create a countdown timer that counts down for 60 seconds (optionally skippable by the user). That part of the code works. How do I make it so an action is taken upon the completion of the countdown timer (the same action as the button does, ending the activity).
public void startCountdown(int total, final int increase) {
final TimerClassExtended timer = new TimerClassExtended(total,1000);
timer.start();
Button skip = (Button)findViewById(R.id.skip);
skip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
timer.cancel();
setResult(RESULT_OK);
finish();
}
});
}
Figured it out, had to modify the following line. But I can’t answer myself for 8 hours…
For future reference, TimerClassExtended is just a class I made that extends CountDownTimer so I could add extra methods that I needed.
final TimerClassExtended timer = new TimerClassExtended(total,1000) {
public void onFinish() {
setResult(RESULT_OK);
finish();
}
};
Since I had a custom class I added the following: