MapFragment.getMapAsync and the Android screen rotate mess
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 11 Jan 2015 00:39:40 +0000 (01:39 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 11 Jan 2015 00:39:40 +0000 (01:39 +0100)
app/src/main/java/name/gumartinm/weather/information/activity/MapActivity.java

index c686982..7369196 100644 (file)
@@ -194,6 +194,7 @@ public class MapActivity extends FragmentActivity implements
 
         // The Android rotate screen mess.
         this.mMapActivityOnMapReadyCallback.onDestroy();
+        this.mButtonsUpdate.onDestroy();
     }
        
     public void onClickSaveLocation(final View v) {
@@ -474,10 +475,6 @@ public class MapActivity extends FragmentActivity implements
             this.mapActivity.mMap.animateCamera(CameraUpdateFactory.zoomIn());
             this.mapActivity.mMap.animateCamera(CameraUpdateFactory.zoomTo(8), 2000, null);
         }
-
-        private WeatherLocation getLocation() {
-            return this.weatherLocation;
-        }
     }
 
     private class ButtonsUpdate {
@@ -488,6 +485,11 @@ public class MapActivity extends FragmentActivity implements
         }
 
         private void doUpdate() {
+            if (this.mapActivity == null) {
+                // Do nothing
+                return;
+            }
+
             if (this.mapActivity.mMap == null) {
                 final Button getLocationButton = (Button) this.mapActivity.findViewById(R.id.weather_map_button_getlocation);
                 final Button saveLocationButton = (Button) this.mapActivity.findViewById(R.id.weather_map_button_savelocation);
@@ -510,5 +512,9 @@ public class MapActivity extends FragmentActivity implements
                 }
             }
         }
+
+        private void onDestroy() {
+            this.mapActivity = null;
+        }
     }
 }