죄송합니다.Java의 문제 TimerTask Interval
Android 애플리케이션을 만들 때 Java TimerTask를 구현 중입니다. 코드는 복잡하지 않습니다. 간격에 도달하면 SMS & 이메일을 보냅니다.
보내는 SMS/이메일 간격과 관련하여 몇 가지 옵션이 있습니다. 5 분, 15 분, 30 분, 1 시간 및 2 시간.
5 분 15 분 (나는 그것을 밀리로 변환 함)을 사용해 보았지만 아무런 문제가 발생하지 않았습니다. 그것은 sms를 보내고 매 5 분마다 정확하게 15 분 이메일을 보낸다. 그리고 나는 timertask를 사용하는 데 문제가 없다는 것을 증명한다.
그러나 30 분 이상으로 변경했습니다. 내 응용 프로그램은 SMS/전자 메일을 보낼 수 없습니다. 타이머가 제대로 작동하지 않는 것처럼 보였습니다.
타이머 작업 사용시 간격 제한이 있습니까 ??
이것은 내 코드 단편입니다.
private void activateNotificationByInterval(int notificationInterval) {
timerNotificationByInterval = new Timer();
timerNotificationByInterval.schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
// coba
// if (oldLatitude != childLatitude
// && oldLongitude != childLongitude) {
if ((enableSMS == true)) {
sendSMS();
}
if ((enableEmail == true)) {
GMailSender email = new GMailSender(sender, senderPassword);
try {
email.sendMail(emailSubject + childsName, SMSMessage
+ " " + childlLocation + "\nLatitude: "
+ childLatitude + "\nLongitude: "
+ childLongitude, sender, destination);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
mpv.changeLastLocation(childLatitude, childLongitude);
// buat method untuk menangkap lokasi pertama
oldLatitude = childLatitude;
oldLongitude = childLongitude;
// } else {
// System.out.println("Lokasi Lama Berpengaruh");
// }
}
}, 0, notificationInterval);
}
* 참고 : notificationInterval milis에 (* 60000)
는 당신이 그것을 해결하는 방법을 말해 줄 수? 고맙습니다.
몇 시간 후 살해 TimerTask를 일부 장치에서 제대로 작동하지 않습니다는. 당신은 AlarmManager에 가야합니다. – Shehzad
조언 해 주셔서 감사합니다. 나는 AlarmManager를 시도 할 것이다. – farissyariati