diff --git a/MyTracks/res/values/do_not_translate.xml b/MyTracks/res/values/do_not_translate.xml index cb00bb80a..e6e472948 100644 --- a/MyTracks/res/values/do_not_translate.xml +++ b/MyTracks/res/values/do_not_translate.xml @@ -50,5 +50,4 @@ limitations under the License. android.intent.action.SAVE android.intent.action.settings.OPEN - android.intent.extra.IGNORE_ILLEGAL_STATE 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 d4207e670..948a94a9f 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java @@ -290,14 +290,8 @@ public class TrackRecordingService extends Service { if (intent.getBooleanExtra(RESUME_TRACK_EXTRA_NAME, false)) { resumeTrack(startId); } else { - try { - // Process actions for controlling the service. - processStartStopIntent(intent); - } catch (IllegalStateException e) { - /* Eat the exception if our sender says to ignore it, e.g., the Widget. */ - if (!intent.getBooleanExtra(getString(R.string.ignore_illegal_state), false)) - throw e; - } + // Process actions for controlling the service. + processStartStopIntent(intent); } } @@ -305,16 +299,24 @@ public class TrackRecordingService extends Service { String action = intent.getAction(); if (isNewTrackAction(action)) { - boolean selectNewTrack = intent.getBooleanExtra(getString(R.string.select_new_track_extra), false); - - startNewTrack(); - if (selectNewTrack) { - prefManager.setSelectedTrack(recordingTrackId); + if (!isTrackInProgress()) { + boolean selectNewTrack = intent.getBooleanExtra(getString(R.string.select_new_track_extra), false); + + startNewTrack(); + if (selectNewTrack) { + prefManager.setSelectedTrack(recordingTrackId); + } } } else if (isEndTrackAction(action)) { - endCurrentTrack(); + if (isTrackInProgress()) { + endCurrentTrack(); + } } } + + private boolean isTrackInProgress() { + return recordingTrackId != -1 || isRecording; + } private boolean isNewTrackAction(String action) { return getString(R.string.start_new_track_action).equals(action); @@ -571,9 +573,6 @@ public class TrackRecordingService extends Service { public long startNewTrack() { Log.d(TAG, "TrackRecordingService.startNewTrack"); - if (recordingTrackId != -1 || isRecording) { - throw new IllegalStateException("A track is already in progress!"); - } long startTime = System.currentTimeMillis(); acquireWakeLock(); @@ -1009,9 +1008,6 @@ public class TrackRecordingService extends Service { private void endCurrentTrack() { Log.d(TAG, "TrackRecordingService.endCurrentTrack"); - if (recordingTrackId == -1 || !isRecording) { - throw new IllegalStateException("No recording track in progress!"); - } announcementExecutor.shutdown(); splitExecutor.shutdown(); diff --git a/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java b/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java index 614f7a7e7..5ee51fdc0 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java +++ b/MyTracks/src/com/google/android/apps/mytracks/widgets/TrackWidgetProvider.java @@ -198,11 +198,6 @@ public class TrackWidgetProvider private void setButtonIntent( RemoteViews views, Context context, int action, int icon, int extra) { Intent intent = new Intent(context, TrackRecordingService.class); - - /* Keeps the TrackRecordingService from throwing back an exception in cases where - * two of the same intents are sent from the user double taping on the widget. */ - intent.putExtra(context.getString(R.string.ignore_illegal_state), true); - intent.setAction(context.getString(action)); if (extra != -1) { intent.putExtra(context.getString(extra), true);