0
  1. is LocationListener.onLocationChanged method is better than any other way of getting Location.

  2. if so is there a better way to use it, so as to get better battery performance.

joseph
  • 123
  • 1
  • 10

1 Answers1

0

I wouldn't know of an alternative to LocationListener.onLocationChanged , maybe you can yourself shed some light on this ?

As for the battery issue, you can call requestLocationUpdates() just less often to avoid battery draining. This call for this contains a variable minDistance (in milliseconds), you should use this one. Please note that observing minDistance was not mandatory until android 4.3 .

For devices with versions prior to 4.3 , you need to

1) stop calling updates in onLocationChanged

@Override
public void onLocationChanged(Location location) {
mLocationManager.removeUpdates(mLocationListener);
}

2) override the method run to introduce a new interval.

 @Override
public void run() {
    // getting location...
    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocationListener);
    // ...once per hour
    mHandler.postDelayed(onRequestLocation, DateUtils.HOUR_IN_MILLIS);
}

For further reference , see the docu for requestLocationUpdates()

Roman
  • 47
  • 2
  • 9