extras/location/src/main/java/com/stanfy/enroscar/location/LocationBinder.java
public void startListening(final Context context) {
    if (DEBUG) { Log.d(TAG, "Start location listening..."); }
    try {
      locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
      if (locationManager == null) { return; }
    } catch (final Exception e) {
      return;
    }
    myHandler = myLooper != null ? new MyHandler(myLooper) : new MyHandler();

    if (listener != null) {
      listener.onLocationStart();
    }

    final Location last = getLastKnown(locationManager);
    if (last != null) { newLocation(last); }

    final Criteria c = new Criteria();
    c.setAltitudeRequired(false);
    c.setSpeedRequired(false);
    c.setBearingRequired(false);
    c.setCostAllowed(false);

    c.setPowerRequirement(Criteria.POWER_LOW);
    c.setAccuracy(Criteria.ACCURACY_COARSE);
    final String coarseProvider = locationManager.getBestProvider(c, false);
    c.setPowerRequirement(Criteria.NO_REQUIREMENT);
    c.setAccuracy(Criteria.ACCURACY_FINE);
    final String fineProvider = locationManager.getBestProvider(c, false);

    if (DEBUG) { Log.d(TAG, "Providers " + coarseProvider + "/" + fineProvider); }
    final long minTime = 60000;
    final int minDistance = 50;
    if (coarseProvider != null) {
      if (DEBUG) { Log.d(TAG, "Register for " + coarseProvider); }
      locationManager.requestLocationUpdates(coarseProvider, minTime, minDistance, coarseListener);
      myHandler.sendEmptyMessageDelayed(MSG_STOP_COARSE_PROVIDER, MAX_COARSE_PROVIDER_LISTEN_TIME);
    }
    if (fineProvider != null) {
      if (DEBUG) { Log.d(TAG, "Register for " + fineProvider); }
      locationManager.requestLocationUpdates(fineProvider, minTime, minDistance, fineListener);
      myHandler.sendEmptyMessageDelayed(MSG_STOP_FINE_PROVIDER, MAX_FINE_PROVIDER_LISTEN_TIME);
    }
  }
public void startListening(final Context context) {
    if (DEBUG) { Log.d(TAG, "Start location listening..."); }
    try {
      locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
      if (locationManager == null) { return; }
    } catch (final Exception e) {
      return;
    }
    myHandler = myLooper != null ? new MyHandler(myLooper) : new MyHandler();

    if (listener != null) {
      listener.onLocationStart();
    }

    final Location last = getLastKnown(locationManager);
    if (last != null) { newLocation(last); }

    final Criteria c = new Criteria();
    c.setAltitudeRequired(false);
    c.setSpeedRequired(false);
    c.setBearingRequired(false);
    c.setCostAllowed(false);

    c.setPowerRequirement(Criteria.POWER_LOW);
    c.setAccuracy(Criteria.ACCURACY_COARSE);
    final String coarseProvider = locationManager.getBestProvider(c, false);
    c.setPowerRequirement(Criteria.NO_REQUIREMENT);
    c.setAccuracy(Criteria.ACCURACY_FINE);
    final String fineProvider = locationManager.getBestProvider(c, false);

    if (DEBUG) { Log.d(TAG, "Providers " + coarseProvider + "/" + fineProvider); }
    final long minTime = 60000;
    final int minDistance = 50;
    if (coarseProvider != null) {
      if (DEBUG) { Log.d(TAG, "Register for " + coarseProvider); }
      locationManager.requestLocationUpdates(coarseProvider, minTime, minDistance, coarseListener);
      myHandler.sendEmptyMessageDelayed(MSG_STOP_COARSE_PROVIDER, MAX_COARSE_PROVIDER_LISTEN_TIME);
    }
    if (fineProvider != null) {
      if (DEBUG) { Log.d(TAG, "Register for " + fineProvider); }
      locationManager.requestLocationUpdates(fineProvider, minTime, minDistance, fineListener);
      myHandler.sendEmptyMessageDelayed(MSG_STOP_FINE_PROVIDER, MAX_FINE_PROVIDER_LISTEN_TIME);
    }
  }
Please call it from the main thread (with looper).
@param context context instance