Make sure there is only one instance of TrackRecordingService at a time.

This commit is contained in:
Bartlomiej Niechwiej
2010-11-21 19:33:14 -08:00
parent cb97847392
commit 224fe0069b
3 changed files with 31 additions and 11 deletions
@@ -90,6 +90,12 @@ public class PreferenceManager implements OnSharedPreferenceChangeListener {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
if (service == null) {
Log.w(MyTracksConstants.TAG,
"onSharedPreferenceChanged: a preference change (key = " + key
+ ") after a call to shutdown()");
return;
}
if (key == null || key.equals(minRecordingDistanceKey)) {
service.setMinRecordingDistance(
sharedPreferences.getInt(
@@ -180,4 +186,10 @@ public class PreferenceManager implements OnSharedPreferenceChangeListener {
.putLong(recordingTrackKey, id)
.commit();
}
public void shutdown() {
sharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
sharedPreferences = null;
service = null;
}
}
@@ -705,15 +705,22 @@ public class TrackRecordingService extends Service implements LocationListener {
@Override
public void onDestroy() {
Log.d(MyTracksConstants.TAG, "TrackRecordingService.onDestroy");
checkLocationListener.cancel();
timer.cancel();
isRecording = false;
showNotification();
prefManager.shutdown();
prefManager = null;
checkLocationListener.cancel();
timer.cancel();
timer.purge();
unregisterLocationListener();
shutdownAnnouncer();
signalManager.shutdown();
signalManager = null;
splitManager.shutdown();
splitManager = null;
releaseWakeLock();
super.onDestroy();
}