谁能告诉我这样做是否安全?我运行一个倒数计时器(CountDownTimer),当计时器达到零时,它必须重新开始,例如倒计时更长的时间。为此,我打电话
timer = new TableCount(nextTime * 1000, 100);
在 onFinish() 方法中。
它运行没有问题,但我担心它可能会导致内存泄漏。我是否应该让计时器触发某种通知它已完成?以下是活动代码中的重要部分:
public class TableActivity extends Activity {
TableCount timer; // the count down timer
protected int nextTime;
...
// somewhere I call this - user clicked the "start" button
timer = new TableCount(nextTime * 1000, 100);
nextTime += 100; // for example
...
public class TableCount extends CountDownTimer
{
public void onFinish() {
... // check if number of iterations has been reached, else:
// start counting down from the next value
timer = new TableCount(nextTime * 1000, 100);
nextTime += 100; // for example
}
}