我有这段代码,我想尝试每小时发送一封电子邮件报告(在示例中为每秒)。如果没有覆盖,请在一小时内重试等。不知何故,我设法打破了 sendUnsendedReports() 中的计时器:它只触发一次。如果我删除对 sendUnsendedReports() 的调用,则计时器工作正常。即使周围有 try-catch 块,计时器也只会触发一次。请指教。
private void createAndScheduleSendReport() {
delayedSendTimer = new Timer();
delayedSendTimer.schedule(new TimerTask() {
@Override
public void run() {
Log.w("UrenRegistratie", "Try to send e-mail...");
try{
sendUnsendedReports();
}
catch(Exception e){
// added try catch block to be sure of uninterupted execution
}
Log.w("UrenRegistratie", "Mail scheduler goes to sleep.");
}
}, 0, 1000);
}