@Override
 public void onResume() {
   super.onResume();
   // if forecast is already downloaded use this one
   if (Helper.isGotForecasts()) {
     updateUiFromStoredForecasts();
   } else {
     setUpLocationClientIfNeeded();
     if (!mLocationClient.isConnected()) {
       mLocationClient.connect();
     }
   }
 }
 @Override
 public void onConnected(Bundle connectionHint) {
   mLocationClient.requestLocationUpdates(REQUEST, this); // LocationListener
   if (getFragmentManager() != null) { // run only if app is active
     getFragmentManager().executePendingTransactions();
   } // to make sure isAdded returns the correct value
   if (isAdded()) { // prevent running if the fragment is not still attached to the activity
     if (Helper.isGotForecasts()) {
       updateUiFromStoredForecasts();
     } else {
       updateUi();
     }
   }
 }
 @Override
 public void setUserVisibleHint(boolean isVisibleToUser) {
   super.setUserVisibleHint(isVisibleToUser);
   if (isVisibleToUser) {
     // if forecast is already downloaded use this one
     if (Helper.isGotForecasts()) {
       updateUiFromStoredForecasts();
     } else {
       setUpLocationClientIfNeeded();
       if (!mLocationClient.isConnected()) {
         mLocationClient.connect();
       } else {
         updateUi();
       }
     }
   }
 }