我想在Back按钮上完成我的CountdownTimer。我知道有一些类似的问题,但这对我的问题没有帮助。
我在onCreate()
@Override
public void onFinish() {
new CountDownTimer(10000, 550) {
@Override
public void onTick(long millisUntilFinished) {
for(int i = 0; i< arr.size(); i++){
Button aga = arr.get(i);
if(aga.getVisibility() == View.VISIBLE){
aga.setVisibility(View.GONE);
}
}
int zufall = (int) (Math.random()*23);
setNextButton(arr.get(zufall));
}
@Override
public void onFinish() {
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
new CountDownTimer(10000, 350) {
@Override
public void onTick(long millisUntilFinished) {
for(int i = 0; i< arr.size(); i++){
Button aga = arr.get(i);
if(aga.getVisibility() == View.VISIBLE){
aga.setVisibility(View.GONE);
}
}
int zufall = (int) (Math.random()*23);
setNextButton(arr.get(zufall));
System.out.println("HHH");
}
@Override
public void onFinish() {
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
Intent highscore = new Intent (MainActivity.this, Highscore_eintragen.class);
highscore.putExtra("count", count);
startActivity(highscore);
}
}.start();
}
}.start();
}
}.start();
现在我需要的是,如果用户在CountdownTimer
期间按下后退按钮来完成我的活动。针对这个问题的任何解决方案?
答案 0 :(得分:2)
调用CountDownTimer.cancel():
http://developer.android.com/reference/android/os/CountDownTimer.html#cancel()
在创建期间存储对活动中当前CountDownTimer实例的引用,以便在Activity中访问它。