title: Android - Getting user Current location in certain time interval
body: <p>I need to get the user current location using gps in certain time interval even after closing the application. i have done using service.<br>
  here is my service class.                                                              </p>
  
  <pre><code>public class MyService extends Service {
  
      private static final String TAG = "BOOMBOOMTESTGPS";
      private LocationManager mLocationManager = null;
      private static final int LOCATION_INTERVAL = 1000;
      private static final float LOCATION_DISTANCE = 0f;
  
      private class LocationListener implements android.location.LocationListener {
          Location mLastLocation;
  
          public LocationListener(String provider) {
              Log.e(TAG, "LocationListener " + provider);
              mLastLocation = new Location(provider);
          }
  
          @Override
          public void onLocationChanged(Location location) {
              Log.e(TAG, "LocationListener " + location);
          }
  
          @Override
          public void onStatusChanged(String provider, int status, Bundle extras) {
              Log.e(TAG, "onStatusChanged " + provider);
          }
  
          @Override
          public void onProviderEnabled(String provider) {
              Log.e(TAG, "onProviderEnabled " + provider);
          }
  
          @Override
          public void onProviderDisabled(String provider) {
              Log.e(TAG, "onProviderDisabled" + provider);
          }
      }
  
      android.location.LocationListener[] mLocationListener = new android.location.LocationListener[]{
              new LocationListener(LocationManager.GPS_PROVIDER), new LocationListener(LocationManager.NETWORK_PROVIDER)
      };
  
      @Nullable
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          Log.e(TAG, "onStartCommand");
          super.onStartCommand(intent, flags, startId);
          return START_STICKY;
      }
  
      @Override
      public void onCreate() {
          Log.e(TAG, "onCreate");
          initializeLocationManagrr();
          try {
  
              mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, LOCATION_INTERVAL, LOCATION_DISTANCE, mLocationListener[0]);
  
          }catch(java.lang.SecurityException ex){
              Log.i(TAG, "fail to request location update, ignore", ex);
          } catch (IllegalArgumentException ex1){
              Log.d(TAG, "gps provider does not exist " + ex1.getMessage());
          }
      }
  
      @Override
      public void onDestroy() {
          Log.e(TAG,"onDestroy");
          super.onDestroy();
          if(mLocationManager!=null){
              for(int i=0;i&lt;mLocationListener.length;i++){
                  try{
                      mLocationManager.removeUpdates(mLocationListener[i]);
                  }catch ( Exception e2){
                      Log.i(TAG, "fail to remove location listners, ignore", e2);
                  }
              }
          }
      }
      private void initializeLocationManagrr(){
          Log.e(TAG,"initializeLocationManagaer");
          if(mLocationManager==null){
              mLocationManager=(LocationManager)getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
          }
      }
   }
  </code></pre>
  
  <p>And am calling this class from MainActivity.java like this                       </p>
  
  <pre><code>startService(new Intent(MainActivity.this,MyService.class));
  </code></pre>
  
  <p>and in  my Log nothing is shown regarding the location.                    </p>
  
  <p>And also i have added the google service config files in my app.<br>
  My main problem is am not getting any user location in my Log cat but the app is running fine.</p>
  
  <p>Can Anyone help me please.</p>