From 215583440388d597b99fac162a3e847e8fda26c7 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Mon, 12 Jan 2015 03:11:55 +0100 Subject: [PATCH] MapFragment.getMapAsync and the Android screen rotate mess --- .../weather/information/activity/MapActivity.java | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/name/gumartinm/weather/information/activity/MapActivity.java b/app/src/main/java/name/gumartinm/weather/information/activity/MapActivity.java index 7369196..0f2b59e 100644 --- a/app/src/main/java/name/gumartinm/weather/information/activity/MapActivity.java +++ b/app/src/main/java/name/gumartinm/weather/information/activity/MapActivity.java @@ -193,8 +193,15 @@ public class MapActivity extends FragmentActivity implements super.onDestroy(); // The Android rotate screen mess. - this.mMapActivityOnMapReadyCallback.onDestroy(); - this.mButtonsUpdate.onDestroy(); + if (this.mMapActivityOnMapReadyCallback != null) { + this.mMapActivityOnMapReadyCallback.onDestroy(); + } + if (this.mButtonsUpdate != null) { + this.mButtonsUpdate.onDestroy(); + } + if (this.mMapUpdate != null) { + this.mMapUpdate.onDestroy(); + } } public void onClickSaveLocation(final View v) { @@ -475,6 +482,14 @@ public class MapActivity extends FragmentActivity implements this.mapActivity.mMap.animateCamera(CameraUpdateFactory.zoomIn()); this.mapActivity.mMap.animateCamera(CameraUpdateFactory.zoomTo(8), 2000, null); } + + /** + * The Android rotate screen mess. Required because the Activity.isDestroyed method exists + * just from API level 17. + */ + private void onDestroy() { + this.mapActivity = null; + } } private class ButtonsUpdate { @@ -513,6 +528,10 @@ public class MapActivity extends FragmentActivity implements } } + /** + * The Android rotate screen mess. Required because the Activity.isDestroyed method exists + * just from API level 17. + */ private void onDestroy() { this.mapActivity = null; } -- 2.1.4