title: How to make an android app run in background when the screen sleeps?
body: <p>I am developing a Tracking app, which keeps tracks of the user by getting his current location for every 3 secs. I am able to fetch the lat long values when the screen is on. but when the screen sleeps. i am unable to fetch the datas.</p>
  
  <p><strong>CODE:</strong></p>
  
  <pre><code>@Override
  public void onLocationChanged(Location location) {
      mLastLocation = location;
      if (mCurrLocationMarker != null)
      {
          mCurrLocationMarker.remove();
      }
      latitude = location.getLatitude();
      longitude = location.getLongitude();
      latLngcurrent = new LatLng(location.getLatitude(), location.getLongitude());
  
      Toast.makeText(context,String.valueOf(latitude)+" "+String.valueOf(longitude), Toast.LENGTH_LONG).show();
  
      Log.d("onLocationChanged", String.format("latitude:%.3f longitude:%.3f",latitude,longitude));
  
  
      Log.d("onLocationChanged", "Exit");
      Toast.makeText(this, "exiting LocationChanged ", Toast.LENGTH_SHORT).show();
      }
  </code></pre>
  
  <p>The above given onLocationChanged method fetches the lat lon values for every 3 seconds. What should i do to make this method run even if the screen sleeps. I have read about Wakelock dont know how to implement it, any help will be appreciated. Thanks in advance.</p>
  
  <p><strong>Note:</strong>  The app runs perfectly when multi tasking is done,</p>