Increased polling frequency in notification service. Added NPE protections.
This commit is contained in:
parent
b69abf9a38
commit
9e4b4cf8d2
@ -204,8 +204,10 @@ public class NotificationService extends Service implements EtdServiceListener {
|
|||||||
|
|
||||||
private void cancelAlarm() {
|
private void cancelAlarm() {
|
||||||
((BartRunnerApplication) getApplication()).setAlarmPending(false);
|
((BartRunnerApplication) getApplication()).setAlarmPending(false);
|
||||||
|
if (mAlarmManager != null) {
|
||||||
mAlarmManager.cancel(mAlarmPendingIntent);
|
mAlarmManager.cancel(mAlarmPendingIntent);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onETDChanged(List<Departure> departures) {
|
public void onETDChanged(List<Departure> departures) {
|
||||||
@ -266,6 +268,11 @@ public class NotificationService extends Service implements EtdServiceListener {
|
|||||||
shutDown(false);
|
shutDown(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Departure must have changed... fire the alarm
|
||||||
|
if (getAlarmClockTime() < System.currentTimeMillis()) {
|
||||||
|
triggerAlarmImmediately();
|
||||||
|
}
|
||||||
|
|
||||||
updateNotification();
|
updateNotification();
|
||||||
|
|
||||||
final int pollIntervalMillis = getPollIntervalMillis();
|
final int pollIntervalMillis = getPollIntervalMillis();
|
||||||
@ -285,8 +292,12 @@ public class NotificationService extends Service implements EtdServiceListener {
|
|||||||
private void shutDown(boolean isBeingDestroyed) {
|
private void shutDown(boolean isBeingDestroyed) {
|
||||||
if (!mHasShutDown) {
|
if (!mHasShutDown) {
|
||||||
mHasShutDown = true;
|
mHasShutDown = true;
|
||||||
|
if (mEtdService != null) {
|
||||||
mEtdService.unregisterListener(this);
|
mEtdService.unregisterListener(this);
|
||||||
|
}
|
||||||
|
if (mNotificationManager != null) {
|
||||||
mNotificationManager.cancel(DEPARTURE_NOTIFICATION_ID);
|
mNotificationManager.cancel(DEPARTURE_NOTIFICATION_ID);
|
||||||
|
}
|
||||||
cancelAlarm();
|
cancelAlarm();
|
||||||
if (!isBeingDestroyed)
|
if (!isBeingDestroyed)
|
||||||
stopSelf();
|
stopSelf();
|
||||||
@ -355,9 +366,9 @@ public class NotificationService extends Service implements EtdServiceListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (secondsToAlarm > 3 * 60) {
|
if (secondsToAlarm > 3 * 60) {
|
||||||
return 30 * 1000;
|
return 15 * 1000;
|
||||||
} else {
|
} else {
|
||||||
return 10 * 1000;
|
return 6 * 1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user