diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index e260a2dd95..be24b0b1e6 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -185,6 +185,14 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa return true; } + @Override + protected void onDestroy() { + // Issue 2657 + super.onDestroy(); + if (!(currentSearchTask == null || currentSearchTask.getStatus() == Status.FINISHED)) { + currentSearchTask.cancel(true); + } + } public Toolbar getClearToolbar(boolean visible) { final Toolbar tb = (Toolbar) findViewById(R.id.poiSplitbar); diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java index a3f9f09c54..80de6071e3 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java @@ -215,6 +215,9 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable if (amenityList.size() == 0 && isAutomaticallyIncreaseSearch()) { int step = 5; while (amenityList.size() == 0 && step-- > 0 && isSearchFurtherAvailable()) { + if (matcher != null && matcher.isCancelled()) { + break; + } amenityList = searchFurther(lat, lon, matcher); } } diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index 87bb661591..9e22b7fc46 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -757,6 +757,10 @@ public class ResourceManager { try { if (!filter.isEmpty()) { for (AmenityIndexRepository index : amenityRepositories.values()) { + if (matcher != null && matcher.isCancelled()) { + searchAmenitiesInProgress = false; + break; + } if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) { List r = index.searchAmenities(MapUtils.get31TileNumberY(topLatitude), MapUtils.get31TileNumberX(leftLongitude), MapUtils.get31TileNumberY(bottomLatitude), @@ -832,6 +836,9 @@ public class ResourceManager { List amenities = new ArrayList(); List list = new ArrayList(); for (AmenityIndexRepository index : amenityRepositories.values()) { + if (matcher != null && matcher.isCancelled()) { + break; + } if (index instanceof AmenityIndexRepositoryBinary) { if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) { if(index.checkContains(lat, lon)){