From 4ea44095df41b257e0db8823a517c3d06e99c6aa Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Tue, 2 Feb 2021 10:47:54 +0800 Subject: [PATCH] 1.1.40 trying to squash native crash in mb via testlab. --- app/build.gradle | 4 ++-- .../com/geeksville/mesh/ui/MapFragment.kt | 21 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 112bb7572..fc08675b3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,8 +31,8 @@ android { applicationId "com.geeksville.mesh" minSdkVersion 21 // The oldest emulator image I have tried is 22 (though 21 probably works) targetSdkVersion 29 - versionCode 20139 // format is Mmmss (where M is 1+the numeric major number - versionName "1.1.39" + versionCode 20140 // format is Mmmss (where M is 1+the numeric major number + versionName "1.1.40" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" // per https://developer.android.com/studio/write/vector-asset-studio diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt index 21d5a650c..7a694e408 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt @@ -136,7 +136,7 @@ class MapFragment : ScreenFragment("Map"), Logging { * Mapbox native code can crash painfully if you ever call a mapbox view function while the view is not actively being show */ private val isViewVisible: Boolean - get() = view != null && isResumed + get() = view != null && isResumed && (mapView?.isDestroyed != false) override fun onViewCreated(viewIn: View, savedInstanceState: Bundle?) { super.onViewCreated(viewIn, savedInstanceState) @@ -145,9 +145,9 @@ class MapFragment : ScreenFragment("Map"), Logging { if ((requireContext().applicationContext as GeeksvilleApplication).isAnalyticsAllowed) { val vIn = viewIn.findViewById(R.id.mapView) mapView = vIn - vIn.onCreate(savedInstanceState) - mapView?.let { v -> + v.onCreate(savedInstanceState) + // Each time the pane is shown start fetching new map info (we do this here instead of // onCreate because getMapAsync can die in native code if the view goes away) v.getMapAsync { map -> @@ -205,14 +205,25 @@ class MapFragment : ScreenFragment("Map"), Logging { } override fun onDestroyView() { - mapView?.onDestroy() super.onDestroyView() + mapView?.onDestroy() } override fun onSaveInstanceState(outState: Bundle) { - mapView?.onSaveInstanceState(outState) + mapView?.let { + if (!it.isDestroyed) + it.onSaveInstanceState(outState) + } super.onSaveInstanceState(outState) } + + override fun onLowMemory() { + mapView?.let { + if (!it.isDestroyed) + it.onLowMemory() + } + super.onLowMemory() + } }