diff --git a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java index 80a10c6224..68030adbbc 100644 --- a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java +++ b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java @@ -59,27 +59,31 @@ public class CurrentPositionHelper { } - private void scheduleRouteSegmentFind(final Location loc){ - if(calculatingThread == Thread.currentThread()) { + private void scheduleRouteSegmentFind(final Location loc) { + if (calculatingThread == Thread.currentThread()) { lastFound = runUpdateInThreadCatch(loc.getLatitude(), loc.getLongitude()); - } else if(calculatingThread == null && loc != null) { - Runnable run = new Runnable() { - @Override - public void run() { - try { - lastFound = runUpdateInThreadCatch(loc.getLatitude(), loc.getLongitude()); - if (lastAskedLocation != loc) { - // refresh and run new task if needed - getLastKnownRouteSegment(lastAskedLocation); + } else if (loc != null) { + if (calculatingThread == null) { + Runnable run = new Runnable() { + @Override + public void run() { + try { + lastFound = runUpdateInThreadCatch(loc.getLatitude(), loc.getLongitude()); + if (lastAskedLocation != loc) { + // refresh and run new task if needed + getLastKnownRouteSegment(lastAskedLocation); + } + } finally { + calculatingThread = null; } - } finally { - calculatingThread = null; } - } - }; - calculatingThread = app.getRoutingHelper().startTaskInRouteThreadIfPossible(run); + }; + calculatingThread = app.getRoutingHelper().startTaskInRouteThreadIfPossible(run); + } else if (!calculatingThread.isAlive()) { + calculatingThread = null; + } } - + } protected RouteDataObject runUpdateInThreadCatch(double latitude, double longitude) { diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 5237072b75..68605a57d5 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -823,8 +823,9 @@ public class RoutingHelper { }, "Calculating position"); //$NON-NLS-1$ currentRunningJob.start(); } + return currentRunningJob; } - return currentRunningJob; + return null; }