From 9e4b4cf8d2318bce6f443576dddf2b18fc17c102 Mon Sep 17 00:00:00 2001 From: Doug Keen Date: Thu, 27 Sep 2012 09:34:28 -0700 Subject: [PATCH] Increased polling frequency in notification service. Added NPE protections. --- .../bart/services/NotificationService.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/com/dougkeen/bart/services/NotificationService.java b/src/com/dougkeen/bart/services/NotificationService.java index 98f41a2..1b1d5d0 100644 --- a/src/com/dougkeen/bart/services/NotificationService.java +++ b/src/com/dougkeen/bart/services/NotificationService.java @@ -204,7 +204,9 @@ public class NotificationService extends Service implements EtdServiceListener { private void cancelAlarm() { ((BartRunnerApplication) getApplication()).setAlarmPending(false); - mAlarmManager.cancel(mAlarmPendingIntent); + if (mAlarmManager != null) { + mAlarmManager.cancel(mAlarmPendingIntent); + } } @Override @@ -266,6 +268,11 @@ public class NotificationService extends Service implements EtdServiceListener { shutDown(false); } + // Departure must have changed... fire the alarm + if (getAlarmClockTime() < System.currentTimeMillis()) { + triggerAlarmImmediately(); + } + updateNotification(); final int pollIntervalMillis = getPollIntervalMillis(); @@ -285,8 +292,12 @@ public class NotificationService extends Service implements EtdServiceListener { private void shutDown(boolean isBeingDestroyed) { if (!mHasShutDown) { mHasShutDown = true; - mEtdService.unregisterListener(this); - mNotificationManager.cancel(DEPARTURE_NOTIFICATION_ID); + if (mEtdService != null) { + mEtdService.unregisterListener(this); + } + if (mNotificationManager != null) { + mNotificationManager.cancel(DEPARTURE_NOTIFICATION_ID); + } cancelAlarm(); if (!isBeingDestroyed) stopSelf(); @@ -355,9 +366,9 @@ public class NotificationService extends Service implements EtdServiceListener { } if (secondsToAlarm > 3 * 60) { - return 30 * 1000; + return 15 * 1000; } else { - return 10 * 1000; + return 6 * 1000; } }