add onDetach-method to MapScaleBarLayer to free resources automatically

removed mapScaleBar.destroy() methods from onDestroy-Activity methods
changed global mapScaleBar-variables to local
This commit is contained in:
Meibes
2020-01-26 16:39:44 +01:00
parent f449a0a6fb
commit ebe98c8990
4 changed files with 9 additions and 24 deletions

View File

@@ -42,7 +42,6 @@ public class GettingStarted extends Activity {
private static final String MAP_FILE = "berlin.map";
private MapView mapView;
private MapScaleBar mapScaleBar;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -69,7 +68,7 @@ public class GettingStarted extends Activity {
mapView.map().setTheme(VtmThemes.DEFAULT);
// Scale bar
mapScaleBar = new DefaultMapScaleBar(mapView.map());
MapScaleBar mapScaleBar = new DefaultMapScaleBar(mapView.map());
MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mapView.map(), mapScaleBar);
mapScaleBarLayer.getRenderer().setPosition(GLViewport.Position.BOTTOM_LEFT);
mapScaleBarLayer.getRenderer().setOffset(5 * CanvasAdapter.getScale(), 0);
@@ -94,8 +93,6 @@ public class GettingStarted extends Activity {
@Override
protected void onDestroy() {
if (mapScaleBar != null)
mapScaleBar.destroy();
mapView.onDestroy();
super.onDestroy();
}

View File

@@ -65,7 +65,6 @@ public class MapsforgeActivity extends MapActivity {
private static final Tag SEA_TAG = new Tag("natural", "sea");
private TileGridLayer mGridLayer;
private DefaultMapScaleBar mMapScaleBar;
private Menu mMenu;
private boolean mS3db;
private VectorTileLayer mTileLayer;
@@ -93,14 +92,6 @@ public class MapsforgeActivity extends MapActivity {
SELECT_MAP_FILE);
}
@Override
protected void onDestroy() {
if (mMapScaleBar != null)
mMapScaleBar.destroy();
super.onDestroy();
}
public static class MapFilePicker extends FilePicker {
public MapFilePicker() {
setFileDisplayFilter(new FilterByFileExtension(".map"));
@@ -197,7 +188,7 @@ public class MapsforgeActivity extends MapActivity {
mMap.layers().add(new BuildingLayer(mMap, mTileLayer));
mMap.layers().add(new LabelLayer(mMap, mTileLayer));
mMapScaleBar = new DefaultMapScaleBar(mMap);
DefaultMapScaleBar mMapScaleBar = new DefaultMapScaleBar(mMap);
mMapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
mMapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE);
mMapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE);

View File

@@ -38,7 +38,6 @@ import org.oscim.theme.ThemeLoader;
import org.oscim.theme.VtmThemes;
public class SimpleMapActivity extends BaseMapActivity {
private DefaultMapScaleBar mapScaleBar;
BuildingLayer mBuildingLayer;
private boolean mShadow;
@@ -71,7 +70,7 @@ public class SimpleMapActivity extends BaseMapActivity {
groupLayer.layers.add(new LabelLayer(mMap, mBaseLayer));
mMap.layers().add(groupLayer);
mapScaleBar = new DefaultMapScaleBar(mMap);
DefaultMapScaleBar mapScaleBar = new DefaultMapScaleBar(mMap);
mapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
mapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE);
mapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE);
@@ -86,14 +85,6 @@ public class SimpleMapActivity extends BaseMapActivity {
mMap.setTheme(VtmThemes.DEFAULT);
}
@Override
protected void onDestroy() {
if (mapScaleBar != null)
mapScaleBar.destroy();
super.onDestroy();
}
void runTheMonkey() {
themes[0] = ThemeLoader.load(VtmThemes.DEFAULT);
themes[1] = ThemeLoader.load(VtmThemes.OSMARENDER);

View File

@@ -62,4 +62,10 @@ public class MapScaleBarLayer extends Layer implements Map.UpdateListener {
mapScaleBar.redrawNeeded = false;
}
@Override
public void onDetach() {
super.onDetach();
mapScaleBar.destroy();
}
}