我想在发生事情时记录并延迟 1 分钟。所以我使用一个计时器和 timertask 住这个:
private Timer _checkTimer;
private boolean _timerStart = false;
private void requestPlayPosterItem(long id) {
//
if(_timerStart && _checkTimer != null ){
_checkTimer.cancel();
}
_checkTimer = new Timer();
_checkTimer.schedule(new TimerTask(){
@Override
public void run() {
_timerStart = false;
// do log
}
}, 30000);
_timerStart = true;
// others -----
}
在活动 onPause() 中,我也取消了计时器:
if(_checkTimer != null && _timerStart){
_checkTimer.cancel();
}
我的问题:_checkTimer 可以重用吗?是否存在资源泄漏(计时器)?