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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user