forked from upstream-mirrors/OpenTracks
Partially fix a nasty bug related to losing a tracking session on service crash.
This commit is contained in:
@@ -46,7 +46,6 @@ import android.content.Intent;
|
|||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
@@ -112,7 +111,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
private AuthManager auth;
|
private AuthManager auth;
|
||||||
private final HashMap<String, AuthManager> authMap =
|
private final HashMap<String, AuthManager> authMap =
|
||||||
new HashMap<String, AuthManager>();
|
new HashMap<String, AuthManager>();
|
||||||
private AccountChooser accountChooser = new AccountChooser();
|
private final AccountChooser accountChooser = new AccountChooser();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Dialogs:
|
* Dialogs:
|
||||||
@@ -186,17 +185,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
trackRecordingService = ITrackRecordingService.Stub.asInterface(service);
|
trackRecordingService = ITrackRecordingService.Stub.asInterface(service);
|
||||||
if (startNewTrackRequested) {
|
if (startNewTrackRequested) {
|
||||||
startNewTrackRequested = false;
|
startNewTrackRequested = false;
|
||||||
try {
|
startRecordingNewTrack();
|
||||||
recordingTrackId = trackRecordingService.startNewTrack();
|
|
||||||
Toast.makeText(MyTracks.this,
|
|
||||||
R.string.status_now_recording, Toast.LENGTH_SHORT).show();
|
|
||||||
setSelectedAndRecordingTrack(recordingTrackId, recordingTrackId);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Toast.makeText(MyTracks.this,
|
|
||||||
R.string.error_unable_to_start_recording, Toast.LENGTH_SHORT)
|
|
||||||
.show();
|
|
||||||
Log.w(MyTracksConstants.TAG, "Unable to start recording.", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,8 +336,8 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
// Called when activity is going into the background, but has not (yet) been
|
// Called when activity is going into the background, but has not (yet) been
|
||||||
// killed. Shouldn't block longer than approx. 2 seconds.
|
// killed. Shouldn't block longer than approx. 2 seconds.
|
||||||
Log.d(MyTracksConstants.TAG, "MyTracks.onPause");
|
Log.d(MyTracksConstants.TAG, "MyTracks.onPause");
|
||||||
super.onPause();
|
|
||||||
tryUnbindTrackRecordingService();
|
tryUnbindTrackRecordingService();
|
||||||
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -356,23 +345,23 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
// Called when the current activity is being displayed or re-displayed
|
// Called when the current activity is being displayed or re-displayed
|
||||||
// to the user.
|
// to the user.
|
||||||
Log.d(MyTracksConstants.TAG, "MyTracks.onResume");
|
Log.d(MyTracksConstants.TAG, "MyTracks.onResume");
|
||||||
super.onResume();
|
|
||||||
tryBindTrackRecordingService();
|
tryBindTrackRecordingService();
|
||||||
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
Log.d(MyTracksConstants.TAG, "MyTracks.onStop");
|
Log.d(MyTracksConstants.TAG, "MyTracks.onStop");
|
||||||
super.onStop();
|
|
||||||
// Clean up any temporary GPX and KML files.
|
// Clean up any temporary GPX and KML files.
|
||||||
cleanTmpDirectory("gpx");
|
cleanTmpDirectory("gpx");
|
||||||
cleanTmpDirectory("kml");
|
cleanTmpDirectory("kml");
|
||||||
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanTmpDirectory(String name) {
|
private void cleanTmpDirectory(String name) {
|
||||||
if (!Environment.getExternalStorageState().equals(
|
if (!Environment.getExternalStorageState().equals(
|
||||||
Environment.MEDIA_MOUNTED)) {
|
Environment.MEDIA_MOUNTED)) {
|
||||||
return; // Can't do anything now.
|
return; // Can't do anything now.
|
||||||
}
|
}
|
||||||
String sep = System.getProperty("file.separator");
|
String sep = System.getProperty("file.separator");
|
||||||
File dir = new File(
|
File dir = new File(
|
||||||
@@ -390,11 +379,6 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
|
||||||
super.onConfigurationChanged(newConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Menu events:
|
* Menu events:
|
||||||
* ============
|
* ============
|
||||||
@@ -1223,6 +1207,20 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
}
|
}
|
||||||
}, account);
|
}, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startRecordingNewTrack() {
|
||||||
|
try {
|
||||||
|
recordingTrackId = trackRecordingService.startNewTrack();
|
||||||
|
Toast.makeText(this, getString(R.string.status_now_recording),
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
setSelectedAndRecordingTrack(recordingTrackId, recordingTrackId);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Toast.makeText(this,
|
||||||
|
getString(R.string.error_unable_to_start_recording),
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
Log.w(MyTracksConstants.TAG, "Unable to start recording.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the track recording service (if not already running) and binds to
|
* Starts the track recording service (if not already running) and binds to
|
||||||
@@ -1235,18 +1233,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
startService(startIntent);
|
startService(startIntent);
|
||||||
tryBindTrackRecordingService();
|
tryBindTrackRecordingService();
|
||||||
} else {
|
} else {
|
||||||
try {
|
startRecordingNewTrack();
|
||||||
recordingTrackId = trackRecordingService.startNewTrack();
|
|
||||||
Toast.makeText(this, getString(R.string.status_now_recording),
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
setSelectedAndRecordingTrack(recordingTrackId, recordingTrackId);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Toast.makeText(this,
|
|
||||||
getString(R.string.error_unable_to_start_recording),
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
Log.e(MyTracksConstants.TAG,
|
|
||||||
"Failed to start track recording service", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -984,7 +984,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
@Override
|
@Override
|
||||||
public void sharedPreferenceChanged(String key) {
|
public void sharedPreferenceChanged(String key) {
|
||||||
Log.d(MyTracksConstants.TAG,
|
Log.d(MyTracksConstants.TAG,
|
||||||
"TrackRecordingService.sharedPrefereneChange");
|
"TrackRecordingService.sharedPreferenceChanged: " + key);
|
||||||
onSharedPreferenceChanged(key);
|
onSharedPreferenceChanged(key);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user