Fix Memory leak caused by duplicated add in LocationListener list

The addLocationListener method didn't check if the LocationListener was
already in the list.

From MapView, if we call setMyLocationEnabled(true), it adds a
LocationListener and onResume adds the same LocationListener again, but
is just removed by onPause.

So LocationListener is added twice but removed just once, so
LocationServices singleton keeps an instance of the the LocationListener
that is never released.
This commit is contained in:
jaumeolba
2016-01-26 13:40:37 +01:00
committed by Tobrun
parent 8e5862bd5d
commit 026e6a7560

View File

@@ -117,7 +117,9 @@ public class LocationServices implements com.mapzen.android.lost.api.LocationLis
* @param locationListener LocationListener
*/
public void addLocationListener(@NonNull LocationListener locationListener) {
this.locationListeners.add(locationListener);
if(!this.locationListeners.contains(locationListener)){
this.locationListeners.add(locationListener);
}
}
/**