From 08294e8ada8cc71c1a0b22dcb8c91ac60d707627 Mon Sep 17 00:00:00 2001 From: Sandor Dornbush Date: Mon, 5 Sep 2011 21:37:09 -0700 Subject: [PATCH] Avoid RejectedExecutionException. --- .../apps/mytracks/services/TrackRecordingService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java index ee63dca09..a0f2010ee 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java @@ -153,6 +153,9 @@ public class TrackRecordingService extends Service { @Override public void onLocationChanged(final Location location) { + if (executorService.isShutdown() || executorService.isTerminated()) { + return; + } executorService.submit( new Runnable() { @Override @@ -342,7 +345,6 @@ public class TrackRecordingService extends Service { timer.purge(); unregisterLocationListener(); shutdownTaskExecutors(); - executorService.shutdown(); if (sensorManager != null) { sensorManager.shutdown(); sensorManager = null; @@ -358,6 +360,8 @@ public class TrackRecordingService extends Service { // This should be the last operation. releaseWakeLock(); + // Shutdown the executor service last to avoid sending events to a dead executor. + executorService.shutdown(); super.onDestroy(); }