From 09764aee4b1174918f68401672df202d058813b6 Mon Sep 17 00:00:00 2001 From: HilaryN Date: Mon, 7 Dec 2020 17:45:14 +0000 Subject: [PATCH] Moved detach to onDestroy --- .../main/java/net/cyclestreets/CycleMapFragment.kt | 5 +++++ .../java/net/cyclestreets/MainNavDrawerActivity.kt | 8 +++++--- .../java/net/cyclestreets/views/CycleMapView.java | 12 +++++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/libraries/cyclestreets-fragments/src/main/java/net/cyclestreets/CycleMapFragment.kt b/libraries/cyclestreets-fragments/src/main/java/net/cyclestreets/CycleMapFragment.kt index 8ebad1913..b2ebe209b 100644 --- a/libraries/cyclestreets-fragments/src/main/java/net/cyclestreets/CycleMapFragment.kt +++ b/libraries/cyclestreets-fragments/src/main/java/net/cyclestreets/CycleMapFragment.kt @@ -108,6 +108,11 @@ open class CycleMapFragment : Fragment(), Undoable { map!!.onResume() } + override fun onDestroy() { + map!!.onDestroy() + super.onDestroy() + } + override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { if (map != null) map!!.onCreateOptionsMenu(menu) diff --git a/libraries/cyclestreets-fragments/src/main/java/net/cyclestreets/MainNavDrawerActivity.kt b/libraries/cyclestreets-fragments/src/main/java/net/cyclestreets/MainNavDrawerActivity.kt index b6ccbff78..2a12c3785 100644 --- a/libraries/cyclestreets-fragments/src/main/java/net/cyclestreets/MainNavDrawerActivity.kt +++ b/libraries/cyclestreets-fragments/src/main/java/net/cyclestreets/MainNavDrawerActivity.kt @@ -89,6 +89,11 @@ abstract class MainNavDrawerActivity : AppCompatActivity(), OnNavigationItemSele else if (CycleStreetsAppSupport.isNewVersion()) onNewVersion() CycleStreetsAppSupport.splashScreenSeen() + + val selectedItem = prefs().getInt(DRAWER_ITEMID_SELECTED_KEY, R.id.nav_journey_planner) + // If menu item not found, show journey planner + if (!showPage(selectedItem)) + showPage(R.id.nav_journey_planner) } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -184,9 +189,6 @@ abstract class MainNavDrawerActivity : AppCompatActivity(), OnNavigationItemSele } public override fun onResume() { - val selectedItem = prefs().getInt(DRAWER_ITEMID_SELECTED_KEY, R.id.nav_journey_planner) - if (!showPage(selectedItem)) - showPage(R.id.nav_journey_planner) super.onResume() Route.registerListener(this) setBlogStateTitle() diff --git a/libraries/cyclestreets-view/src/main/java/net/cyclestreets/views/CycleMapView.java b/libraries/cyclestreets-view/src/main/java/net/cyclestreets/views/CycleMapView.java index 2d9e68735..cbcd50912 100644 --- a/libraries/cyclestreets-view/src/main/java/net/cyclestreets/views/CycleMapView.java +++ b/libraries/cyclestreets-view/src/main/java/net/cyclestreets/views/CycleMapView.java @@ -180,9 +180,10 @@ public void onPause() { // These lines effectively shut down the map. // This object needs to be discarded and re-created on resuming. - getTileProvider().detach(); - getTileProvider().clearTileCache(); - BitmapPool.getInstance().clearBitmapPool(); + // Moved to onDestroy (todo remove commented out lines below) + //getTileProvider().detach(); + //getTileProvider().clearTileCache(); + //BitmapPool.getInstance().clearBitmapPool(); } public void onResume() { @@ -227,6 +228,11 @@ public void onTick(long unfinished) { } }.start(); } + public void onDestroy() { + getTileProvider().detach(); + //getTileProvider().clearTileCache(); todo not needed as this is in detach + BitmapPool.getInstance().clearBitmapPool(); + } //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// public void onCreateOptionsMenu(final Menu menu) {