title: Using Google Play Services LocationClient in background service
body: <p>My app is designed to track user's location periodically and send it to server, Recently I changed my code with Google play services Location API.</p>
  
  <p>I created the locationclient and connected to the service in onStartCommand</p>
  
  <pre><code>public int onStartCommand(Intent intent, int flags, int startId) {
      setUpLocationClientIfNeeded();
      if(!mLocationClient.isConnected() || !mLocationClient.isConnecting())
      mLocationClient.connect();
      return START_STICKY;
  
  }
  </code></pre>
  
  <p>and in onConnected method, I send a location request,</p>
  
  <pre><code>@Override
  public void onConnected(Bundle arg0) {
      System.out.println("Connected ...");
      mLocationClient.requestLocationUpdates(REQUEST, this);
  
  }
  </code></pre>
  
  <p>The REQUEST object is,</p>
  
  <pre><code> private static final LocationRequest REQUEST = LocationRequest.create()
        .setInterval(5*60*1000)      // 5 minutes
        .setFastestInterval(3*60*1000) // 3 minutes
        .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
  </code></pre>
  
  <p>Now the issue is,</p>
  
  <ol>
  <li>the onLocationChanged method is not getting called at the given interval i.e 5 minutes or the fastest interval 3 minutes.  From the log I could see, its getting called only twice or thrice after that its not getting called at all ( I checked after 1 hour). </li>
  </ol>
  
  <p>What is the issue with my above code?. ( I couldnt see any log for 'disconnected' also)</p>
  
  <ol>
  <li>To solve this, I tried to use alarmmanager to call the task periodically. Now how to get a single location update through Locationclient from a broadcastreceiver. (locationclient.getLastlocation() only return last stored location but it is not requesting a new location) </li>
  </ol>