title: Android to update geofence regularly
body: <p>I am reading through documentation from here. </p>
  
  <p><a href="https://developer.android.com/training/location/geofencing" rel="nofollow noreferrer">https://developer.android.com/training/location/geofencing</a></p>
  
  <p>It can update me location for my geofence when I run that service. Problem is I need to monitor continuously. So, I am thinking to do timer in my service and check my geofence regularly. But, I think it will definitely drain battery.</p>
  
  <p>I don't want to monitor location and instead, I need android OS to update me whether user goes inside my geofence just like iOS. Is there any way to implement that ?</p>
  
  <pre><code>public class GeofenceTransitionsIntentService extends IntentService {
      // ...
      protected void onHandleIntent(Intent intent) {
          GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
          if (geofencingEvent.hasError()) {
              String errorMessage = GeofenceErrorMessages.getErrorString(this,
                      geofencingEvent.getErrorCode());
              Log.e(TAG, errorMessage);
              return;
          }
  
          // Get the transition type.
          int geofenceTransition = geofencingEvent.getGeofenceTransition();
  
          // Test that the reported transition was of interest.
          if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ||
                  geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
  
              // Get the geofences that were triggered. A single event can trigger
              // multiple geofences.
              List&lt;Geofence&gt; triggeringGeofences = geofencingEvent.getTriggeringGeofences();
  
              // Get the transition details as a String.
              String geofenceTransitionDetails = getGeofenceTransitionDetails(
                      this,
                      geofenceTransition,
                      triggeringGeofences
              );
  
              // Send notification and log the transition details.
              sendNotification(geofenceTransitionDetails);
              Log.i(TAG, geofenceTransitionDetails);
          } else {
              // Log the error.
              Log.e(TAG, getString(R.string.geofence_transition_invalid_type,
                      geofenceTransition));
          }
      }
  </code></pre>