Fix gpx lock in the start of a recording. Use a handler thread

to obtain locationListener callbacks.
This commit is contained in:
Jimmy Shih
2013-03-07 11:40:14 -08:00
parent 89e01a706e
commit e44d2875cc
@@ -250,12 +250,8 @@ public class TrackRecordingService extends Service {
@Override @Override
public void run() { public void run() {
if (isRecording() && !isPaused()) { if (isRecording() && !isPaused()) {
handler.post(new Runnable() {
public void run() {
registerLocationListener(); registerLocationListener();
} }
});
}
} }
}; };
@@ -962,6 +958,12 @@ public class TrackRecordingService extends Service {
* Registers the location listener. * Registers the location listener.
*/ */
private void registerLocationListener() { private void registerLocationListener() {
/*
* Use the handler so the requestLocationUpdaets locationListener will be
* invoked on the handler thread.
*/
handler.post(new Runnable() {
public void run() {
unregisterLocationListener(); unregisterLocationListener();
if (myTracksLocationManager == null) { if (myTracksLocationManager == null) {
@@ -970,13 +972,16 @@ public class TrackRecordingService extends Service {
} }
try { try {
long interval = locationListenerPolicy.getDesiredPollingInterval(); long interval = locationListenerPolicy.getDesiredPollingInterval();
myTracksLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, interval, myTracksLocationManager.requestLocationUpdates(
locationListenerPolicy.getMinDistance(), locationListener); LocationManager.GPS_PROVIDER, interval, locationListenerPolicy.getMinDistance(),
locationListener);
currentRecordingInterval = interval; currentRecordingInterval = interval;
} catch (RuntimeException e) { } catch (RuntimeException e) {
Log.e(TAG, "Could not register location listener.", e); Log.e(TAG, "Could not register location listener.", e);
} }
} }
});
}
/** /**
* Unregisters the location manager. * Unregisters the location manager.