title: How to get gps location every 30 mins in the background
body: <p>I am trying to make an app that will send your gps location to a webserver every x mins. Im confused about how I should do this. Do I use a timer or a different service to call the get gps function every x mins?</p>
  
  <p>This is what I'm using to get the gps signal </p>
  
  <pre><code>LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
                  Criteria criteria = new Criteria();
                  criteria.setAccuracy(Criteria.ACCURACY_FINE);
                  String bestProvider = locationManager.getBestProvider(criteria,
                          false);
                  LocationListener loc_listener = new LocationListener() {
  
                      @Override
                      public void onStatusChanged(String provider, int status,
                              Bundle extras) {
                          // TODO Auto-generated method stub
  
                      }
  
                      @Override
                      public void onProviderEnabled(String provider) {
                          // TODO Auto-generated method stub
  
                      }
  
                      @Override
                      public void onProviderDisabled(String provider) {
                          // TODO Auto-generated method stub
  
                      }
  
                      @Override
                      public void onLocationChanged(Location location) {
                          // TODO Auto-generated method stub
  
                      }
                  };
                  try {
                      Looper.prepare();
                      locationManager.requestLocationUpdates(bestProvider, 0, 0,
                              loc_listener);
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
                  Location location = locationManager
                          .getLastKnownLocation(bestProvider);
  </code></pre>