forked from upstream-mirrors/OpenTracks
TrackRecordingService: move service restart handling into method.
This commit is contained in:
@@ -189,17 +189,7 @@ public class TrackRecordingService extends Service {
|
|||||||
PreferencesUtils.register(this, sharedPreferenceChangeListener);
|
PreferencesUtils.register(this, sharedPreferenceChangeListener);
|
||||||
sharedPreferenceChangeListener.onSharedPreferenceChanged(null, null);
|
sharedPreferenceChangeListener.onSharedPreferenceChanged(null, null);
|
||||||
|
|
||||||
// Try to restart the previous recording track in case the service has been restarted by the system, which can sometimes happen.
|
restartTrackAfterServiceRestart();
|
||||||
Track track = contentProviderUtils.getTrack(recordingTrackId);
|
|
||||||
if (track != null) {
|
|
||||||
restartTrack(track);
|
|
||||||
} else {
|
|
||||||
if (isRecording()) {
|
|
||||||
Log.w(TAG, "track is null, but recordingTrackId not -1L. " + recordingTrackId);
|
|
||||||
updateRecordingState(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, true);
|
|
||||||
}
|
|
||||||
showNotification(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -375,7 +365,20 @@ public class TrackRecordingService extends Service {
|
|||||||
startRecording();
|
startRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restartTrack(Track track) {
|
/**
|
||||||
|
* Try to restart the previous recording track in case the service has been restarted by the system, which can sometimes happen.
|
||||||
|
*/
|
||||||
|
private void restartTrackAfterServiceRestart() {
|
||||||
|
Track track = contentProviderUtils.getTrack(recordingTrackId);
|
||||||
|
if (track == null) {
|
||||||
|
if (isRecording()) {
|
||||||
|
Log.w(TAG, "track is null, but recordingTrackId not -1L. " + recordingTrackId);
|
||||||
|
updateRecordingState(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, true);
|
||||||
|
}
|
||||||
|
showNotification(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Log.d(TAG, "Restarting track: " + track.getId());
|
Log.d(TAG, "Restarting track: " + track.getId());
|
||||||
|
|
||||||
trackStatisticsUpdater = new TrackStatisticsUpdater(track.getTrackStatistics().getStartTime_ms());
|
trackStatisticsUpdater = new TrackStatisticsUpdater(track.getTrackStatistics().getStartTime_ms());
|
||||||
|
|||||||
Reference in New Issue
Block a user